How to post content to WordPress using Python and Rest API

To get familiar with WordPress REST API, I fired up Python started playing with the requests23 module, the elegant and simple HTTP library for Python, built for human beings. Python and the WordPress REST API Handbook68 gave me enough information to get started.

The default cookies authentication mechanism would not work with Python and you need to install a plugin for this sort of application. See this tutorial on how to use the WordPress OAuth 1.0a plugin.

For a quick demo, the Application Passwords plugin for WordPress126 is the easiest choice. The installation is straightforward, and the instructions to generate a password for the client application are quite simple to follow. I needed to modify the .htaccess file35 due to the way my DreamPress site is configured. Notice: the password generated by the plugin contains white spaces, and they are part of the password. Once the WordPress authentication is taken care of, it’s all much easier.