AttributeError: ‘str’ object has no attribute ‘items’

You are passing in a stringheaders can’t ever be a JSON encoded string, it is always a Python dictionary.

The print results are deceptive; JSON encoded objects look a lot like Python dictionary representations but they are far from the same thing.

The requests API clearly states that headers must be a dictionary:

  • headers – (optional) Dictionary of HTTP Headers to send with the Request.

JSON data is something you’d send as content to another server, not something you’d use to communicate with a Python API.

Leave a Comment