Login to WordPress from Python

This article was posted more than 1 year ago. Please keep in mind that the information on this page may be outdated, insecure, or just plain wrong today.

I’ve been trying to learn some Python and have been tinkering with the requests module. Here is how I am able to log into a webpage, such as WordPress.

import requests
 url = "https://techish.net/wp-login.php"
 redirect_to  = "https://techish.net/wp-admin/"
 with requests.Session() as session:
     post = session.post(url, data={
         'log': 'admin',
         'pwd': 'password',
         'redirect_to': redirect_to
         }, allow_redirects=True)
     get = session.get(redirect_to, cookies=post.cookies)
     print(get.text)

#python, #wordpress