1

I'm trying to update posts using python and API, the issue that I keep getting code 200 but the post doesn't actually get updated!

here is my code:

import requests
import json
import base64

url ='http://www.***.com/wp-json/wp/v2'

username="------"
password="------"

creds = username + ':' + password
cred_token = base64.b64encode(creds.encode())

header = {'Authorization': 'Basic ' + cred_token.decode('utf-8')}


postID = "36559"
post = {
 'content' : "Hello, this content updated."
}

blog = requests.post(url + "/posts/" + postID , headers=header, json=post)
print(blog)

I also tried, but kept getting response 404:

blog = requests.post(url + "/" + postID , headers=header, json=post)

Edit - Solution: the issue was that the url had http and not https, it seems i have to use the https version, although its weird I kept getting 200 response. Now it works

2
  • I don’t know Python, but it looks like you’re using the POST method. To update posts you need to send a PUT request. Oct 19, 2022 at 11:16
  • @JacobPeattie same issue, I get response 200, but the post doesn't change
    – Fadi
    Oct 19, 2022 at 13:05

1 Answer 1

0

Edit - Solution: the issue was that the url had http and not https, it seems i have to use the https version, although its weird I kept getting 200 response before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.