gpt4 book ai didi

python requests.post 没有值的数据不起作用

转载 作者:行者123 更新时间:2023-12-01 00:12:06 73 4
gpt4 key购买 nike

我怎样才能只将表单数据的 key 发布到像网站本身这样的服务器?

http_post_text_or_only_key_of_dict

In [1]: from requests import Request

In [2]: req = Request('POST', 'http://www.google.com', data={'json':''}).prepare()

In [3]: req.headers, req.body
Out[3]:
({'Content-Length': '5', 'Content-Type': 'application/x-www-form-urlencoded'},
'json=')

In [4]: req = Request('POST', 'http://www.google.com', data={'json':None}).prepare()

In [5]: req.headers, req.body
Out[5]: ({'Content-Type': 'application/x-www-form-urlencoded'}, '')

“Content-Length”不能等于 key 长度,例如 4。并且,我怎样才能使主体等于“json”?谢谢大家

最佳答案

来自the documentation :

There are times that you may want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.

就您而言,这意味着这样做:

req = Request('POST', 'http://www.google.com', data='json').prepare()

关于python requests.post 没有值的数据不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59572581/

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