KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How do you pass a csrftoken with the python module Requests? This is what I have but it's not working, and I'm not sure which parameter to pass it into (data, headers, auth...) import requests from bs4 import BeautifulSoup URL = 'https://portal.bitcasa.com/login' client = requests.session(config={'verbose': sys.stderr}) # Retrieve the CSRF token first soup = BeautifulSoup(client.get('https://portal.bitcasa.com/login').content) csrftoken = soup.find('input', dict(name='csrfmiddlewaretoken'))['value'] login_data = dict(username=EMAIL, password=PASSWORD, csrfmiddlewaretoken=csrftoken) r = client.post(URL, data=login_data, headers={"Referer": "foo"}) Same error message every time. <h1>Forbidden <span>(403)</span></h1> <p>CSRF verification failed. Request aborted.</p>
Tags (comma-separated)
Save Edits
Cancel