I want to remotely create and delete post from my wordpress site. I am using this plugin for authentication : https://wordpress.org/plugins/rest-api-oauth1/. I successfully generated all codes and successfully deleted one post using POSTMAN. However when I am unable to do the same using python3
I have checked 100 times, all codes were same in postman and python
please help.

def get_oauth(login):
    oauth = OAuth1(login["consumer_key"],
                client_secret=login["consumer_secret"],
                resource_owner_key=login["oauth_token"],
                resource_owner_secret=login["oauth_token_secret"])
    pp.pprint(login)
    pp.pprint(oauth)
    return oauth


if __name__ == "__main__":
    login = {
        "consumer_key" : "...",
        "consumer_secret" : "...",
        "oauth_token" : "...",
        "oauth_token_secret" : "..."
    }
    oauth = get_oauth(login)

    r = requests.delete('http://myserver.com/wp-json/wp/v2/posts/1', auth=oauth)
    pp.pprint(r.request.headers)
    print(r.request.headers)
    #pp.pprint(r.headers)
    pp.pprint(r.json())

Response:

{ 'code': 'rest_cannot_delete',
'data': {'status': 401},
'message': 'Sorry, you are not allowed to delete this post.'}

Read more here: wordpress Api works with postaman but not with script


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: