gpt4 book ai didi

Python 请求在尝试使用数据 POST 时出现 TypeError

转载 作者:行者123 更新时间:2023-12-01 08:14:02 26 4
gpt4 key购买 nike

我正在尝试在页面上进行表单登录,但不断收到以下类型错误。我已阅读Python Requests package文档,当我打印数据字典时,它看起来像是一个有效的示例。我不确定出了什么问题。这是我的回溯代码:

import requests

accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
acceptlang = "en-US,en;q=0.9"
url = 'https://httpbin.org/post'
userid = 'username'
passwd = 'password'

headers = {
'Accept': accept,
'Accept-Language': acceptlang,
}

data = {userid: fakeuserid, passwd: fakepasswd}

>>> print(data)
{'username': 'fakeuser@example.com', 'password': '0#CCJyy3^5Tu(Z'}
>>> response = requests.post(url, headers, data=data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: post() got multiple values for argument 'data'

当我仅使用(url,标题)或(url,data=data)发布时,发布成功。我不确定这里发生了什么。

最佳答案

根据requests API ,看起来好像您的 headers 参数需要关键字,如果没有该关键字,post() 会假定它是 data。试试这个:

response = requests.post(url, headers=headers, data=data)

关于Python 请求在尝试使用数据 POST 时出现 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55073556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com