Python WordPress.com API: 403 Error (User cannot publish posts) when publishing

Python WordPress.com API: 403 Error (User cannot publish posts) when publishing
# Example code used for publishing (some values changed)
import requests, json, base64
BLOG_URL = "https://aidentist.wordpress.com"
WP_USER = "sonpp" # My WP.com username
WP_PASSWORD = "k" # App password used (tried regenerating)
api_url = f"https://public-api.wordpress.com/rest/v1.1/sites/{BLOG_URL.split('//')[1]}/posts/new"
post_data = {"title": "Test Post", "content": "Test content", "status": "publish"}
credentials = f"{WP_USER}:{WP_PASSWORD}"

    token = base64.b64encode(credentials.encode()).decode()
    headers = {"Authorization": f"Basic {token}", "Content-Type": "application/json"}
    try:
        response = requests.post(api_url, headers=headers, json=post_data)
        response.raise_for_status()
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
        # Error output includes:
        # HTTP Status Code: 403
        # Response Body: {"error": "unauthorized", "message": "User cannot publish posts"}

Hello,

I'm encountering a persistent 400 error when trying to use the Vertex AI Gemini API (Vision) via the Python client library (google-cloud-aiplatform).

Project Info:

ID: mineral-math-455909-s6 Number: 931095336936 (This number appears in the error message) Region: asia-northeast3 Problem: When running Python code similar to the snippet below, I consistently get a 400 Project '931095336936' is not allowed to use Publisher Model... error. The error references the Project Number, even though my code initializes with the Project ID. What I've confirmed:

The Vertex AI API is Enabled for this project (mineral-math-455909-s6). The account used has Owner role for the project. The Billing Account (Free Trial) is active and linked. Tried both authentication methods (ADC and Service Account Key) multiple times with various checks/resets; the error persists. The error occurs with other models (gemini-1.0-pro) and regions (us-central1) as well. Has anyone else experienced a similar platform-level issue where Vertex AI throws a 400 error referencing the Project Number being disallowed, despite all standard permissions and settings appearing correct? Are there any known quirks (Free Trial, specific regions, new projects) or other configuration areas to investigate?

(Note: I have also contacted Google Cloud Support, but seeking community insights.)

Thanks!

Answer

Question 1 (Simplified English Version - WordPress 403 Error)

Title: Python WordPress.com API: 403 Error (User cannot publish posts) when publishing

Body:

Hi everyone,

I'm trying to automatically publish posts to my WordPress.com blog using Python (requests library) and an Application Password.

However, when I send a POST request to the /posts/new endpoint using code similar to the example below, I consistently get a 403 Forbidden - User cannot publish posts error.

Python

# Example code used for publishing (some values changed)
import requests, json, base64
BLOG_URL = "https://aidentist.wordpress.com"
WP_USER = "sonpp" # My WP.com username
WP_PASSWORD = "k" # App password used (tried regenerating)
api_url = f"https://public-api.wordpress.com/rest/v1.1/sites/{BLOG_URL.split('//')[1]}/posts/new"
post_data = {"title": "Test Post", "content": "Test content", "status": "publish"}
credentials = f"{WP_USER}:{WP_PASSWORD}"
token = base64.b64encode(credentials.encode()).decode()
headers = {"Authorization": f"Basic {token}", "Content-Type": "application/json"}
try:
    response = requests.post(api_url, headers=headers, json=post_data)
    response.raise_for_status()
except requests.exceptions.RequestException as e:
    print(f"Error: {e}")
    # Error output includes:
    # HTTP Status Code: 403
    # Response Body: {"error": "unauthorized", "message": "User cannot publish posts"}

What I've checked:

  • I can publish posts manually from the WordPress admin dashboard with the same account.

  • I've regenerated the Application Password multiple times.

  • My WordPress.com site is publicly launched (not private or "coming soon").

  • Trying to save as 'draft' instead of 'publish' also resulted in the same 403 error.

  • (Note: Basic GET requests using the same authentication method, like fetching site info, seemed to work fine).

Does anyone know other common reasons for this specific 403 - User cannot publish posts error when trying to publish via the API? Are there other things I should check, like hidden scopes for Application Passwords or potential Free plan limitations related to API publishing?

Thanks for any insights!

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles