更新时间:2023-12-02 23:14:10
您正在传递字符串; headers
不能永远是JSON编码的字符串,它始终是Python字典.
You are passing in a string; headers
can't ever be a JSON encoded string, it is always a Python dictionary.
print
结果具有欺骗性; JSON编码的对象看起来很像Python字典表示形式,但是它们距离同一事物远.
The print
results are deceptive; JSON encoded objects look a lot like Python dictionary representations but they are far from the same thing.
requests
API 明确指出
The requests
API clearly states that headers
must be a dictionary:
headers
–(可选)与Request
一起发送的HTTP标头字典.
headers
– (optional) Dictionary of HTTP Headers to send with theRequest
.
JSON数据是您要作为内容发送到另一台服务器的内容,而不是用于与Python API通信的内容.
JSON data is something you'd send as content to another server, not something you'd use to communicate with a Python API.