• Hi,
    I’ve been strugging with this for a few hours, and the Support team directed me here, even though I have a .Com business account. So I hope this request is both appropriate for the forum, and that my explanation is sufficient for advise to be given.

    The Situation:
    I’d like to post some content, from a Python program resident on my laptop currently, into an existing page.

    I have installed the WP REST API – OAuth 1.0a Server, and setup an Application Password.

    I have read the documentation for the REST API (I’m new to that construct) and have reviewed advise on the stackoverflow forums.

    I am able to make HTTP requests, using the Python script, to the page and receive responses.

    The Problem:
    My attempts to update (i.e. put some content on the page) have been unsuccessful. I receive a HTTP200 code but nothing has changed on the page itself.

    The scratchpad code is below.

    
    user = 'myappuser'
    pythonapp = 'myappuserpwd'
    post = {
            'title': 'First REST API post',
            'status': 'publish',
            'content': '<p>this is the content post</p>',
            }
    url = 'https://mypage.org/'
    url = url + "mypageToEdit"
    r = requests.post(url, auth=HTTPBasicAuth(user, pythonapp), json=post)
    print(r)
    print(r.headers)
    r.close()
    
    • This topic was modified 7 years, 10 months ago by Jan Dembowski. Reason: Fixes formatting
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Did you try hitting the actual REST API URL?

    Sending a POST to just “mypage.org” isn’t going to do anything, but sending a POST to the actual REST endpoint located at /wp-json/wp/v2/posts/ might do the trick.

    Thread Starter stephenk289

    (@stephenk289)

    Thanks Samuel. I’ve tried a number of constructs with the /wp-json/wp/v2/pages end-point but without success. Do you have any steer on how that might look in the above code?

    Moderator bcworkz

    (@bcworkz)

    POSTing to something like example.com/wp-json/wp/v2/pages is what you want to do. I think where the problem lies is in authentication. Using HTTPBasicAuth as you are in requests.post() will not do the job. You need to be providing a proper OAuth token. Please review Setting Up and Using OAuth 1.0a Authentication.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using REST API with Python3 – no update being made’ is closed to new replies.