79583855

Date: 2025-04-20 23:41:04
Score: 3
Natty:
Report link

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:

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!

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • RegEx Blacklisted phrase (2): Does anyone know
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: 손현아