IslanderMark
Junior Member
- Sep 2, 2020
- 101
- 24
if anyone can maybe help with this issue I'm encountering when running my python script that would be great, I feel like I have tried everything at this point.
I am simply trying to do some very basic posting to my site, it used to work but then I decided to switch to a VPS and now it wont work.
When I run it I get a 200 status code, I will include the output below the code. But the code does nothing, it doesn't actually post the post, it just prints out the 200 code and that it.
I also was using Wordpress xmlrpc but stopped with that cause I got an annoying error of 301 moved permanently and cant figure out that either, so if you have insight on that too i would go back to that if I can get it fixed
But the code I am trying now is as such, any info would be appreciated:
Output:
I am simply trying to do some very basic posting to my site, it used to work but then I decided to switch to a VPS and now it wont work.
When I run it I get a 200 status code, I will include the output below the code. But the code does nothing, it doesn't actually post the post, it just prints out the 200 code and that it.
I also was using Wordpress xmlrpc but stopped with that cause I got an annoying error of 301 moved permanently and cant figure out that either, so if you have insight on that too i would go back to that if I can get it fixed
But the code I am trying now is as such, any info would be appreciated:
import requests
import json
# Set the endpoint URL of your WordPress website
url = 'https://MYSITE.com/wp-json/wp/v2/posts/'
# Set the credentials for authentication
username = 'USR'
password = 'PASS'
# Set the post content
title = 'Test post'
content = 'This is the content of my new post.'
# Set the request headers
headers = {
'Content-Type': 'application/json'
}
# Set the request data
data = {
'title': title,
'content': content,
'status': 'draft'
}
# Send the request
response = requests.post(url, json=data, headers=headers, auth=(username, password))
print (response.headers)
print (response.text)
# Check the response
if response.status_code == 201:
print('Post created successfully!')
else:
print('Error creating the post. Status Code:', response.status_code)
print('Error message:', response.text)
Output:
[]
Error creating the post. Status Code: 200
Error message: []
Last edited: