Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3.x通过请求POST连接到帐户_Python_Session - Fatal编程技术网

Python3.x通过请求POST连接到帐户

Python3.x通过请求POST连接到帐户,python,session,Python,Session,我正在尝试连接到adidas.fr上的帐户,为此我编写了以下脚本: session = requests.Session() user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36" session.headers["User-Agent"]=user_agent result=se

我正在尝试连接到adidas.fr上的帐户,为此我编写了以下脚本:

session = requests.Session()

user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"

session.headers["User-Agent"]=user_agent

result=session.get('https://cp.adidas.fr/web/eCom/fr_FR/loadsignin')

tree = html.fromstring(result.text)

authenticity_token = tree.xpath("//input[@name='CSRFToken']/@value")

print(authenticity_token[0])

login_data = {
    'username': 'mail@gmail.com',
    'password': 'pass',
    'CSRFToken' :str(authenticity_token[0]),
             }

R=session.post('https://cp.adidas.fr/web/eCom/fr_FR/loadsignin',data=login_data)

print(R.text)

然后我尝试进入一个需要连接但无法访问的页面。所以我觉得我的帖子要求不好,但我找不到我做错了什么。有人能帮忙吗?谢谢

如果您需要
post()
,为什么要使用
get()
?对不起,我写的时候它的帖子只是个错误。您得到了什么结果?你看到了什么文本?也许有一些有用的信息。您确定它使用字段名
用户名
,“passwor”吗?您确定它不发送其他字段-即使是空字段?服务器也可以检查此字段。您可以在Chrome/Firefox中使用
DevTools
(选项卡
网络
)来检查向浏览器发送的数据。是的,我使用篡改数据来生成有效负载