python - 我使用了 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)
解决方案
不要直接放数据,而是使用:
import json
response=requests.post('https://data.geoiq.io/dataapis/v1.0/covid/availabledistricts',json.dumps(data))
推荐阅读
- applescript - 根据applescript函数的输出设置变量
- python - Python opencv检测具有交叉点的形状
- azure - 有没有办法通过策略阻止将用户添加到 Azure 资源?
- python - 为什么 nc 文件中的 lat 和 lon 维度会因组装两个 nc 文件而改变?
- java - Univocity Parser - 如何在解析的 bean 中获取行号
- ios - 使用安全的 UITextField 输入密码时,键盘显示延迟较长
- swift - 如何在 SwiftUI 中使用 Swift 手动倒带、停止和转发 Gif
- php - Woocommerce 弱密码复选框(店面子主题)
- python - 有人可以帮我解决关于我在 python 中对我的 API 的发布请求的错误吗?
- javascript - 更改对象数组中的键名 - JS