Post 错误请求在 python 中休息 api
Post Bad Request rest api in python
我正在尝试 post 在 Python 中通过 REST API 一些数据。
data.json
{
"LastModifiedAt": "2020-12-21T20:19:45.335Z",
...
...
}
我正在使用以下代码 POST 数据。
with open('data.json') as fh:
data = json.load(fh)
headers = {
'Content-Type': 'application/json',
'X-API-Key':'ABC=='
}
response = requests.post('https://myurl.net/api/v1/resource/int_key/endpoint', headers=headers,data=data)
我总是得到关注作为回应status_code = 400
{
"ModelState": {
"line": [
"Unexpected character encountered while parsing value: L. Path '', line 0, position 0."
]
},
"Message": "The request is invalid."
}
我该如何调试它?根据 API 文档,我的 URL 是正确的。为什么它 return“错误请求”状态代码?
我用 json
替换了 data
并且成功了。
response = requests.post('https://myurl.net/api/v1/resource/int_key/endpoint', headers=headers,
json=data)
我按照 AndroidDev 的建议使用 Postman 进行调试。
我正在尝试 post 在 Python 中通过 REST API 一些数据。
data.json
{
"LastModifiedAt": "2020-12-21T20:19:45.335Z",
...
...
}
我正在使用以下代码 POST 数据。
with open('data.json') as fh:
data = json.load(fh)
headers = {
'Content-Type': 'application/json',
'X-API-Key':'ABC=='
}
response = requests.post('https://myurl.net/api/v1/resource/int_key/endpoint', headers=headers,data=data)
我总是得到关注作为回应status_code = 400
{
"ModelState": {
"line": [
"Unexpected character encountered while parsing value: L. Path '', line 0, position 0."
]
},
"Message": "The request is invalid."
}
我该如何调试它?根据 API 文档,我的 URL 是正确的。为什么它 return“错误请求”状态代码?
我用 json
替换了 data
并且成功了。
response = requests.post('https://myurl.net/api/v1/resource/int_key/endpoint', headers=headers,
json=data)
我按照 AndroidDev 的建议使用 Postman 进行调试。