Code: Select all
wp_creds = f'{wp_user}:{wp_pass}'
wp_token = base64.b64encode(wp_creds.encode()).decode('utf-8')
headers = {
'Authorization': f'Basic {wp_token}',
'Content-Type': 'application/json'
}
post_data = {
'title': 'Test Post from Python',
'content': 'This post was created using dual-authentication over HTTPS.',
'status': 'publish'
}
response = requests.post(
f'{base_url}/posts',
auth=HTTPBasicAuth(server_user, server_pass), # server-level auth
headers=headers, # WP-level auth
json=post_data
)
< /code>
Dieser Code scheint für die Serverautorisierung zu funktionieren, versucht aber auch die Serveranmeldeinformationen für die WordPress -Autorisierung, was zu einem 500 -Fehler wie folgt führt: < /p>
Status Code: 500
Response Body: {"code":"invalid_username","message":"Error: The username [server username] is not registered on this site. If you are unsure of your username, try your email address instead.","data":null}