[Python] 403 Forbidden when creating post via WordPress.com REST API using App Password...

Discussão em 'Python' iniciado por Stack, Junho 29, 2025.

  1. Stack

    Stack Membro Participativo

    How can I fix this and allow API access via App Passwords to publish posts on my Jetpack-enabled site using the REST API? Is there a hidden step to fully connect Jetpack to WordPress.com?

    Python code:

    import requests
    from requests.auth import HTTPBasicAuth

    email = "hernandesmjunior@gmail.com"
    app_password = "my app password here" # the real app password, with spaces
    site = "cafecomite.wordpress.com" # original name of the site

    url = f"https://public-api.wordpress.com/rest/v1.1/sites/{site}/posts/new"

    data = {
    "title": "Test Post via API",
    "content": "Trying to publish a post via API using App Password",
    "status": "draft"
    }

    response = requests.post(url, auth=HTTPBasicAuth(email, app_password), data=data)

    print(response.status_code)
    print(response.text)


    Response:

    403
    {"error":"unauthorized","message":"User cannot edit posts"}


    More context:

    My site URL is: romanticosradicais.com

    It was originally created as cafecomite.wordpress.com and is mapped to a custom domain

    I have a Premium plan on WordPress.com

    I'm using an admin user (hernandesmjunior@gmail.com)

    I created a new App Password at wordpress.com/settings/security

    I’m using Basic Auth with email and App Password

    Jetpack is installed and appears to be active

    However, Jetpack does not show any full dashboard or “connected” status

    Continue reading...

Compartilhe esta Página