Last active
October 1, 2020 01:06
-
-
Save NanoDano/cf368a7374a6963677c9 to your computer and use it in GitHub Desktop.
Python Requests Log In to Drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What a helpful snippet!, thanks a lot for publishing it!