question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'set' object has no attribute 'items'

See original GitHub issue

fresh pip install requests. version 2.12.4. This works in postman.

import requests
url = 'https://api.spotify.com/v1/audio-analysis/4JpKVNYnVcJ8tuMKjAj50A'
headers = {'Authorization', 'Bearer TOKEN-HERE'}
r = requests.get(url, headers=headers)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-0b5138b50602> in <module>()
      1 url = 'https://api.spotify.com/v1/audio-analysis/4JpKVNYnVcJ8tuMKjAj50A'
      2 headers = {'Authorization', 'Bearer TOKEN-HERE'}
----> 3 r = requests.get(url, headers=headers)

c:\python27\lib\site-packages\requests\api.pyc in get(url, params, **kwargs)
     68 
     69     kwargs.setdefault('allow_redirects', True)
---> 70     return request('get', url, params=params, **kwargs)
     71 
     72 

c:\python27\lib\site-packages\requests\api.pyc in request(method, url, **kwargs)
     54     # cases, and look like a memory leak in others.
     55     with sessions.Session() as session:
---> 56         return session.request(method=method, url=url, **kwargs)
     57 
     58 

c:\python27\lib\site-packages\requests\sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    472             hooks = hooks,
    473         )
--> 474         prep = self.prepare_request(req)
    475 
    476         proxies = proxies or {}

c:\python27\lib\site-packages\requests\sessions.pyc in prepare_request(self, request)
    405             auth=merge_setting(auth, self.auth),
    406             cookies=merged_cookies,
--> 407             hooks=merge_hooks(request.hooks, self.hooks),
    408         )
    409         return p

c:\python27\lib\site-packages\requests\models.pyc in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
    301         self.prepare_method(method)
    302         self.prepare_url(url, params)
--> 303         self.prepare_headers(headers)
    304         self.prepare_cookies(cookies)
    305         self.prepare_body(data, files, json)

c:\python27\lib\site-packages\requests\models.pyc in prepare_headers(self, headers)
    423         self.headers = CaseInsensitiveDict()
    424         if headers:
--> 425             for header in headers.items():
    426                 # Raise exception on invalid header value.
    427                 check_header_validity(header)

AttributeError: 'set' object has no attribute 'items'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
nateprewittcommented, Jan 9, 2017

Hey @codespaced, thanks for opening this issue. It looks like you used a comma instead of a colon to separate the key and value in your header. This is creating a set object instead of the dictionary we’re expecting. Replacing that should solve your issue.

3reactions
makwanaparth94commented, Feb 28, 2018

hey i am facing the same isuues but not able to get where i am facing attribute errors:

self.token= ‘ywlGaT0X44WGEps98WDN8xyFMmJgfGTehKxT5heiq_A7yqa_xwM9z6s2ouB1R7LprEYaTtXoILzx713kYhvoOxQrPLsRuvEAhnHfpc0sRonNXRYJgD91P8c2_mJJJ58MYs2TiMCEXlByG2ODRrb9e5OA35l74HXAegMabFJE7GnLX_4ZCxD2EygFP8LKqamdfao66QXAmXW60nwWYOF7g3bPdQNH3eK2siY9yODd_pFJ2IpLxBiadEFvAWZj5Y’

self.headers = {‘content-type’: ‘application/json’, ‘Authorization’: ‘token {}’.format(self.token)}

getting an error like 👍 def test_api_get(self): # A get request (json example):

  response = requests.get(self.myurl, headers=self.header)

E AttributeError: ‘CL_API’ object has no attribute ‘header’

Please give me some inputs on it

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'set' object has no attribute 'items' - Stack Overflow
Well the error itself is saying there is no attribute called items() . So try and remove .items() from self.changes.items() docs.python.org/3/library/stdtypes.
Read more >
AttributeError: 'set' object has no attribute 'items' | bobbyhadz
The Python "AttributeError: 'set' object has no attribute 'items'" occurs when we create a set object instead of a dictionary.
Read more >
AttributeError: 'set' object has no attribute 'items - Python Forum
Hello, the headers argument should be a dictionary, but you assigned the headers variable to a set with a single string argument in...
Read more >
Got a AttributeError: 'set' object has no attribute 'keys' while ...
Got a AttributeError: 'set' object has no attribute 'keys' while running the code, any way to fix it? : r/learnpython.
Read more >
Python Sets(With Examples) Tutorial - KnowledgeHut
A Set object contains one or more items, which may be of same or ... s1.add("TurboGears") AttributeError: 'frozenset' object has no attribute 'add'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found