",data={'key':''}) 但输出显示 Unrecognized token 'key': was expected ('true','false'or'null,python,python-3.x,python-requests"/>

首页 > 解决方案 > 我使用了 response=requests.post("",data={'key':''}) 但输出显示 Unrecognized token 'key': was expected ('true','false'or'null

问题描述

这是我使用的代码:

import requests
data={'key':'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtYWlsSxyxylbnRpdHk.....ZGtoYW4xNjIwMDBAZ21haWwuY29tIn0.RumJjxNP9_E2vCTkayKc0btm50ggeTGw5ICv7bsktv4'}
response=requests.post('https://data.geoiq.io/dataapis/v1.0/covid/availabledistricts',data)
print(response)
print(response.content)

这是我得到的输出:

<Response [400]>
b'{"message": "Could not parse request body into json: Unrecognized token \\\'key\\\': was expecting (\\\'true\\\', \\\'false\\\' or \\\'null\\\')\\n at [Source: (byte[])\\"key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtYWlsSWRlbnRpdHk.....WhhZGtoYW4xNjIwMDBAZ21haWwuY29tIn0.RumJjxNP9_E2vCTkayKc0btm50ggeTGw5ICv7bsktv4\\"; line: 1, column: 5]"}'

(我特意更改了API KEY)

标签: pythonpython-3.xpython-requests

解决方案


不要直接放数据,而是使用:

import json
response=requests.post('https://data.geoiq.io/dataapis/v1.0/covid/availabledistricts',json.dumps(data)) 

推荐阅读