[GH-ISSUE #193] simple code from readthedocs got exception #97

Closed
opened 2026-02-27 23:20:49 +03:00 by kerem · 6 comments
Owner

Originally created by @zsdonghao on GitHub (May 30, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/193

Hi when I run the simple code from readthedocs as follow:

import spotipy
import sys

spotify = spotipy.Spotify()

if len(sys.argv) > 1:
    name = ' '.join(sys.argv[1:])
else:
    name = 'Radiohead'

results = spotify.search(q='artist:' + name, type='artist')
items = results['artists']['items']
if len(items) > 0:
    artist = items[0]
    print(artist['name'], artist['images'][0]['url'])

I got this exception:

Traceback (most recent call last):
  File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 119, in _internal_call
    r.raise_for_status()
  File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/search?q=artist%3ARadiohead&offset=0&type=artist&limit=10

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 19, in <module>
    results = spotify.search(q='artist:' + name, type='artist')
  File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 339, in search
    return self._get('search', q=q, limit=limit, offset=offset, type=type, market=market)
  File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 146, in _get
    return self._internal_call('GET', url, payload, kwargs)
  File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 124, in _internal_call
    headers=r.headers)
spotipy.client.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/search?q=artist%3ARadiohead&offset=0&type=artist&limit=10:
 No token provided

Anyone know why?
Many thanks~

Originally created by @zsdonghao on GitHub (May 30, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/193 Hi when I run the simple code from readthedocs as follow: ```python import spotipy import sys spotify = spotipy.Spotify() if len(sys.argv) > 1: name = ' '.join(sys.argv[1:]) else: name = 'Radiohead' results = spotify.search(q='artist:' + name, type='artist') items = results['artists']['items'] if len(items) > 0: artist = items[0] print(artist['name'], artist['images'][0]['url']) ``` I got this exception: ``` Traceback (most recent call last): File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 119, in _internal_call r.raise_for_status() File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/requests/models.py", line 844, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/search?q=artist%3ARadiohead&offset=0&type=artist&limit=10 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 19, in <module> results = spotify.search(q='artist:' + name, type='artist') File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 339, in search return self._get('search', q=q, limit=limit, offset=offset, type=type, market=market) File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 146, in _get return self._internal_call('GET', url, payload, kwargs) File "/Users/haodong/Documents/Projects/python-workspace/env3/lib/python3.4/site-packages/spotipy/client.py", line 124, in _internal_call headers=r.headers) spotipy.client.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/search?q=artist%3ARadiohead&offset=0&type=artist&limit=10: No token provided ``` Anyone know why? Many thanks~
kerem 2026-02-27 23:20:49 +03:00
Author
Owner
<!-- gh-comment-id:304750128 --> @gise88 commented on GitHub (May 30, 2017): Is because of this: https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/
Author
Owner

@zsdonghao commented on GitHub (May 30, 2017):

thank you for the super quick reply ..

<!-- gh-comment-id:304752085 --> @zsdonghao commented on GitHub (May 30, 2017): thank you for the super quick reply ..
Author
Owner

@gise88 commented on GitHub (May 30, 2017):

Np for the reply...
But I think that this issue should remains open until all documentation and examples have been fixed

<!-- gh-comment-id:304752793 --> @gise88 commented on GitHub (May 30, 2017): Np for the reply... But I think that this issue should remains open until all documentation and examples have been fixed
Author
Owner

@pannous commented on GitHub (Dec 30, 2017):

so this API is currently broken?

<!-- gh-comment-id:354540831 --> @pannous commented on GitHub (Dec 30, 2017): so this API is currently broken?
Author
Owner

@mateusrangel commented on GitHub (Mar 20, 2018):

import spotipy
import sys
from spotipy.oauth2 import SpotifyClientCredentials

client_credentials_manager = SpotifyClientCredentials(client_id='YOUR CLIENT ID HERE',
                                                      client_secret='YOUR CLIENT SECRET HERE')
spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)


if len(sys.argv) > 1:
    name = ' '.join(sys.argv[1:])
else:
    name = 'Radiohead'

results = spotify.search(q='artist:' + name, type='artist')
items = results['artists']['items']
if len(items) > 0:
    artist = items[0]
    print(artist['name'], artist['images'][0]['url'])

@zsdonghao Nowadays that's how we should authenticate our scripts with the new spotify API rules

@pannous No

<!-- gh-comment-id:374701938 --> @mateusrangel commented on GitHub (Mar 20, 2018): ``` python import spotipy import sys from spotipy.oauth2 import SpotifyClientCredentials client_credentials_manager = SpotifyClientCredentials(client_id='YOUR CLIENT ID HERE', client_secret='YOUR CLIENT SECRET HERE') spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager) if len(sys.argv) > 1: name = ' '.join(sys.argv[1:]) else: name = 'Radiohead' results = spotify.search(q='artist:' + name, type='artist') items = results['artists']['items'] if len(items) > 0: artist = items[0] print(artist['name'], artist['images'][0]['url']) ``` @zsdonghao Nowadays that's how we should authenticate our scripts with the new spotify API rules @pannous No
Author
Owner

@mateusrangel commented on GitHub (Mar 20, 2018):

Alisha Ukani made a pull request fixing a bunch of examples including yours

#244

Apparently the repository owner @plamere is away from the repo

These "hello world" examples are crucial for the newcomers

<!-- gh-comment-id:374757072 --> @mateusrangel commented on GitHub (Mar 20, 2018): Alisha Ukani made a pull request fixing a bunch of examples including yours #244 Apparently the repository owner @plamere is away from the repo These "hello world" examples are crucial for the newcomers
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#97
No description provided.