如何通过 python 模块请求传递 csrftoken?这就是我所拥有的,但它不起作用,我不确定将它传递给哪个参数(数据、标题、身份验证......)
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"})
每次都出现同样的错误信息。
<h1>Forbidden <span>(403)</span></h1>
<p>CSRF verification failed. Request aborted.</p>