mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #690] Error 401: No Token Provided #409
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#409
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @amittenak47 on GitHub (Jun 10, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/690
Describe the bug
The code works and sends POST request to add items, 100 at a time, to the playlist up until the count 3700/7384. Then the response states there is no token provided.
Your code
Authentication:
spotify_oauth = spotipy.SpotifyOAuth(client_id, client_secret, redirect_uri, scope=scope, cache_path=cache)Tried many different parameters, only auth, only auth_manager, only oauth_manager, but same result
spotify_client = spotipy.Spotify(auth=token_info['access_token'], oauth_manager=spotify_oauth, auth_manager=spotify_oauth, retries=5, status_retries=5)Adding from list of URI (items) to a playlist:
i = 0 while len(track_list) > 0: tracks = track_list[i:i + 100] items = [track[1] for track in tracks] spotify_client.playlist_add_items(playlist_id, items) del track_list[i:i + 100] i += 100 time.sleep(1)Expected behavior
The code should add songs until the full count of the list of items, 7384, is reached.
Output
During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/student/anaconda3/envs/personal/lib/python3.8/site-packages/bottle.py", line 868, in _handle return route.call(**args) File "/home/student/anaconda3/envs/personal/lib/python3.8/site-packages/bottle.py", line 1748, in wrapper rv = callback(*a, **ka) File "/home/student/PycharmProjects/spotify/album_playlist.py", line 111, in index add_to_playlist(spotify_client, track_list, playlist_id) File "/home/student/PycharmProjects/spotify/album_playlist.py", line 88, in add_to_playlist spotify_client.playlist_add_items(playlist_id, items) File "/home/student/anaconda3/envs/personal/lib/python3.8/site-packages/spotipy/client.py", line 1025, in playlist_add_items return self._post( File "/home/student/anaconda3/envs/personal/lib/python3.8/site-packages/spotipy/client.py", line 296, in _post return self._internal_call("POST", url, payload, kwargs) File "/home/student/anaconda3/envs/personal/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/6kgveTd5tGGabdZEtbBToS/tracks: Error parsing JSON., reason: None 127.0.0.1 - - [10/Jun/2021 08:00:39] "GET /?code=AQDnoZnRBtHounNyMyuOfDd-Y2YgbsaUHQ1Tq3W0Mj0lHgSwKt8V5W3_-bhCnHpILZ14lzKqi-X-zMvNjGLJezZt_1gkp2IfV3cKoieqQJ1Ng724FkDeT-gAfscmnCCsTAQIbC38XUUt_a4i1urJP2gatl5MI0ze8hJt0F3wvJNB92-oRhMdygrduFqiyePg4Ro HTTP/1.1" 500 942{ "error": { "status": 401, "message": "No token provided" } }Environment:
Additional context
After looking at the cached token, the "expires_in": 3600 key:value seems to match the number of entries before the server responds with "No token provided"
@Peter-Schorn commented on GitHub (Jun 14, 2021):
Read the documentation. It's very clear about how to authorize your app.
@amittenak47 commented on GitHub (Jun 14, 2021):
I didn't make any error in usage of the library. I found and corrected the issue already. The error was using del in conjunction with incrementing variable i. Simple error I overlooked.
@Peter-Schorn commented on GitHub (Jun 14, 2021):
That's not true. The following should never be used:
You should only ever use one of the
auth,oauth_manager,auth_manager, andclient_credentials_managerparameters inSpotify.__init__. The latter three are all aliases that point to the same underlying attribute. Furthermore, you should generally not useauthbecause then the access token will not be automatically refreshed for you.@amittenak47 commented on GitHub (Jun 14, 2021):
I did only use "auth" originally, as per the documentation, but was still getting the error, which I know now was due to a more foolish mistake. I tried to search the documentation and code to determine whether to use the other parameters, but I didn't find anything. I was just trying things out to see what would work and posted the last version of my code snippet here.
However, thank you for clearing up the correct usage. I was confused about the difference between
oauth_managerandauth_manager. I think that info may be useful to others in the "Authorization Code Flow" and "Client Credentials Flow" sections of the documentation.@Peter-Schorn commented on GitHub (Jun 14, 2021):
You're absolutely right that including three different parameters that alias each other is extremely confusing and terrible API design. For this reason, the
oauth_managerandclient_credentials_managerparameters have been removed in thev3branch, which contains changes for the upcoming version 3 release. We can't make this change inmasterbecause it would be a backwards incompatible change.