相关疑难解决方法(0)

使用python请求传递csrftoken

你如何通过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"})
Run Code Online (Sandbox Code Playgroud)

每次都有相同的错误消息.

<h1>Forbidden <span>(403)</span></h1>
<p>CSRF verification failed. Request aborted.</p>
Run Code Online (Sandbox Code Playgroud)

python csrf python-requests

43
推荐指数
1
解决办法
6万
查看次数

标签 统计

csrf ×1

python ×1

python-requests ×1