Skip to content

Instantly share code, notes, and snippets.

@NanoDano
Last active October 1, 2020 01:06
Show Gist options
  • Save NanoDano/cf368a7374a6963677c9 to your computer and use it in GitHub Desktop.
Save NanoDano/cf368a7374a6963677c9 to your computer and use it in GitHub Desktop.
Python Requests Log In to Drupal
import requests
postData = {
'name': 'username',
'pass': 'secret!',
'form_id': 'user_login',
'op': 'Log in'
}
loginUrl = 'http://www.some-drupal-site.com/user'
session = requests.Session()
response = session.post(loginUrl, data=postData)
print(response.text)
print(response.headers)
print(session.cookies) # The session cookie is stored for subsequent requests
@jedihe
Copy link

jedihe commented Mar 29, 2016

What a helpful snippet!, thanks a lot for publishing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment