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'
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.
Yup, this is strictly a Python syntax problem and not a Requests issue. Thanks @nateprewitt. :D
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 :+1:
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
I also have a similar error and I don't know why.
from bs4 import BeautifulSoup
import requests
headers = {"User Agent:" 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}
def price_check():
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text()
print(title.strip())
price_check()
You have a typo in how you're writing your headers value.
headers = {"User Agent:" 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}
Should be
headers = {"User Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}
Look very closely
Most helpful comment
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.