从Requests 2.4.2及更高版本开始,您可以在调用中使用’json’参数,从而使其更简单。
>>> import requests>>> r = requests.post('http://httpbin.org/post', json={"key": "value"})>>> r.status_pre200>>> r.json(){'args': {}, 'data': '{"key": "value"}', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '16', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.4.3 CPython/3.4.0', 'X-Request-Id': 'xx-xx-xx'}, 'json': {'key': 'value'}, 'origin': 'x.x.x.x', 'url': 'http://httpbin.org/post'}编辑:此功能已添加到官方文档中。您可以在此处查看:请求文档



