WordPress authentication plugin setup
First, install the WordPress REST API Authentication
wordpress plugin, which you can find by searching for WordPress REST API Authentication
:
Then you need to open the plugin configuration page. Open Plugins
in the WordPress admin panel, locate the WordPress REST API Authentication
plugin and click Configure
Select Basic Authentication
:
Then click Next
on the top right:
and click Finish
on the next page:
Setup in Python
Assuming you have a WordPress user admin
with password abc123
we can modify our code from How to get WordPress posts as JSON using Python & the WordPress REST API in order to query a non-public endpoint:
import requests import base64 # Compute basic authentication header auth_header = b"Basic " + base64.b64encode(b"admin:abc123") # posts is a list of JSON objects, each representing a post posts = requests.get("https://mydomain.com/wp-json/wp/v2/posts", params={"context": "edit"}, headers={"Authorization": auth_header}).json()