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!