python3请求返回400 Bad Request

时间:2018-04-12 17:05:39

标签: python json curl python-requests

使用curl我得到哈希

curl https://bootstrap.pypa.io/get-pip.py | python

使用Python请求返回400

$ curl "http://127.0.0.1:8002/hash/" -X POST -d 'data={"key":"value"}'
{
  "hash": "9724c1e20e6e3e4d7f57ed25f9d4efb006e508590d528c90da597f6a775c13e5"
}

1 个答案:

答案 0 :(得分:0)

尝试使用{"key":"value"}作为您的数据传入。

那就是:

r = requests.post('http://127.0.0.1:8002/hash/', data = '{"key":"value"}', allow_redirects=False)

请求也可以接受字典对象或元组列表作为其数据参数,这可能比直接输入字符串更容易,更直观。另请注意,您可以使用字典并将其转换为带有json.dumps的json字符串。