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.CommentedOct 19, 2022 at 11:16
  • @JacobPeattie same issue, I get response 200, but the post doesn't change
    – Fadi
    CommentedOct 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.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.