Authentication for creating a wordpress post fails
Authentication for creating a wordpress post fails
I'm struggling to find up to date information or working example to enable a python client to make a simple test post. I've tried creating an Application in the profile section of the user dashboard and using these credentials, as also creating a user. I'm using basic auth and I'm getting a 200 error, but there is never is actual posting taking place.
url = 'http://demo.com/wp-json/wp/v2/posts'
#from Application creation in WP
username = 'remotely'
password = 'XXXX XXXX XXXX XXXX'
#User creds
username = 'auser'
password = 'password'
basic = HTTPBasicAuth(username, password)
basic_pair = username+":"+password
# The post data
data = {
'title': 'My New Post',
'content': 'This is the content of my new post.',
'status': 'draft' # Use 'draft' to save the post as a draft
}
# Send the HTTP request
headers = {"Accept": "application/json", "Content-Type": "application/json"}
payload = json.dumps({
"status":"draft",
"title": "title_translation_text",
"content": "content_translation_text"
})
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=basic
)
print(response.status_code)
print(response.text)
I get a 200 status code
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand