“的错误消息”;HttpMessageTreadableException“;转换JSON请求python时

“的错误消息”;HttpMessageTreadableException“;转换JSON请求python时,python,json,request,Python,Json,Request,我遇到一个json格式的rest API请求问题,无法转换。请求代码如下所示: headers = {"content-type": "application/json","username": "xxx" , "password": "xxx" , "domain": "xxx" } r = requests.post("https://psepmlan1:8446/sepm/api/v1/identity/authenticate",headers=headers,verify=False

我遇到一个json格式的rest API请求问题,无法转换。请求代码如下所示:

headers = {"content-type": "application/json","username": "xxx" , "password": "xxx" , "domain": "xxx" }

r = requests.post("https://psepmlan1:8446/sepm/api/v1/identity/authenticate",headers=headers,verify=False)

print r.content
{"errorCode":"500","errorMessage":"org.springframework.http.converter.HttpMessageNotReadableException"}
我得到的错误如下所示:

headers = {"content-type": "application/json","username": "xxx" , "password": "xxx" , "domain": "xxx" }

r = requests.post("https://psepmlan1:8446/sepm/api/v1/identity/authenticate",headers=headers,verify=False)

print r.content
{"errorCode":"500","errorMessage":"org.springframework.http.converter.HttpMessageNotReadableException"}
我试着阅读了一些关于这个错误的问题,我知道这是关于你传递json请求的方式,但我无法发送正确的请求

有什么建议吗


致以最诚挚的问候

您需要将数据作为json传递到请求正文中,而不是请求头中:

>>> url = 'http://httpbin.org/post'
>>> data = {'user': 'Foo', 'password': 'bar', 'domain': ''}
>>> headers = {'Content-Type': 'application/json'}
>>> response = requests.post(url, headers=headers, data=json.dumps(data))

# httpbin.org/post is a service that accepts a POST request and returns 
# the details of the request as its response
>>> response.json()

{'args': {}, 'data': '{"user": "Foo", "password": "bar", "domain": ""}', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '48', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.12.4'}, 'json': {'domain': '', 'password': 'bar', 'user': 'Foo'}, 'origin': '82.36.117.40', 'url': 'http://httpbin.org/post'}

假设我们有“a.json”。请在发布请求时执行这些操作

json_data=open('a.json', 'r')

values = json.load(json_data)

requests.post(url = url, data = json.dumps(values), headers = header )

这会奏效的。我犯了和你一样的错误

作为系统post请求的一个示例,他们给出了以下内容:post/sepm/api/v1/identity/authenticate HTTP/1.1内容类型:application/json{“username”:“admin”,“password”:“password”,“domain”:“}您找到解决方案了吗?