When I try to run cretin modules in Spotipy I get an Insufficient client scope error message. Spotify gives a 403 client error saying “No Token Provided”
Tried multiple modules only a few work such as the current_user() module but others spit back the Insufficient client scope error.
Tried multiple modules only a few work such as the current_user() module but others spit back the Insufficient client scope error.
import spotipy import os import json import sys import webbrowser import spotipy.util as util from json.decoder import JSONDecodeError username = sys.argv[0] try: token = util.prompt_for_user_token(username) except: os.remove(f".cache-{username}") token = util.prompt_for_user_token(username) spotify = spotipy.Spotify(auth=token) albums = spotify.current_user_saved_albums(limit= 100, offset = 0) userplaylist = spotify.current_user_playlists() spuser= spotify.current_user() class spotifyUser: def __init__(self, userid, followers, playlist): self.userid = userid self.followers = followers self.playlist = playlist self.albums #list all user playlists def all_playlists(playlist): for r in range(len(playlist['items'])): print(playlist['items'][r]['name']) currentuser = spotifyUser(spuser['display_name'],spuser['followers'] ['total'], userplaylist) #all_playlists(currentuser.playlist) print(albums)
When ran results in:
Traceback (most recent call last): File "C:UserscessePycharmProjectsSpotipyvenvlibsite-packagesspotipyclient.py", line 119, in _internal_call r.raise_for_status() File "C:UserscessePycharmProjectsSpotipyvenvlibsite-packagesrequestsmodels.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/albums?limit=100&offset=0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Python37/codes/Testspotipy.py", line 20, in <module> albums = spotify.current_user_saved_albums(limit= 100, offset = 0) File "C:UserscessePycharmProjectsSpotipyvenvlibsite-packagesspotipyclient.py", line 585, in current_user_saved_albums return self._get('me/albums', limit=limit, offset=offset) File "C:UserscessePycharmProjectsSpotipyvenvlibsite-packagesspotipyclient.py", line 146, in _get return self._internal_call('GET', url, payload, kwargs) File "C:UserscessePycharmProjectsSpotipyvenvlibsite-packagesspotipyclient.py", line 124, in _internal_call headers=r.headers) spotipy.client.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/albums?limit=100&offset=0: Insufficient client scope
Advertisement
Answer
Pass an extra arg into your prompt for token call, scope as a string separated by spaces:
token = util.prompt_for_user_token(username, scope="user-library-read <etc>")