且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AttributeError:"str"对象没有属性"items"

更新时间: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 the Request.

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.