[GH-ISSUE #690] Error 401: No Token Provided #409

Closed
opened 2026-02-27 23:22:28 +03:00 by kerem · 5 comments
Owner

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:

  • OS: Ubuntu 18.04.05
  • Python version 3.8
  • spotipy version 2.17.1
  • PyCharm

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"

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:** - OS: Ubuntu 18.04.05 - Python version 3.8 - spotipy version 2.17.1 - PyCharm **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"
kerem 2026-02-27 23:22:28 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@Peter-Schorn commented on GitHub (Jun 14, 2021):

Read the documentation. It's very clear about how to authorize your app.

<!-- gh-comment-id:860326930 --> @Peter-Schorn commented on GitHub (Jun 14, 2021): Read the [documentation](http://spotipy.readthedocs.org/). It's very clear about how to authorize your app.
Author
Owner

@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.

<!-- gh-comment-id:860329202 --> @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.
Author
Owner

@Peter-Schorn commented on GitHub (Jun 14, 2021):

I didn't make any error in usage of the library

That's not true. The following should never be used:

spotify_client = spotipy.Spotify(auth=token_info['access_token'], oauth_manager=spotify_oauth, auth_manager=spotify_oauth, retries=5, status_retries=5)

You should only ever use one of the auth, oauth_manager, auth_manager, and client_credentials_manager parameters in Spotify.__init__. The latter three are all aliases that point to the same underlying attribute. Furthermore, you should generally not use auth because then the access token will not be automatically refreshed for you.

<!-- gh-comment-id:860342492 --> @Peter-Schorn commented on GitHub (Jun 14, 2021): > I didn't make any error in usage of the library That's not true. The following should *never* be used: ``` spotify_client = spotipy.Spotify(auth=token_info['access_token'], oauth_manager=spotify_oauth, auth_manager=spotify_oauth, retries=5, status_retries=5) ``` You should only ever use one of the `auth`, `oauth_manager`, `auth_manager`, and `client_credentials_manager` parameters in `Spotify.__init__`. The latter three are all aliases that point to the same underlying attribute. Furthermore, you should generally not use `auth` because then the access token will not be automatically refreshed for you.
Author
Owner

@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_manager and auth_manager. I think that info may be useful to others in the "Authorization Code Flow" and "Client Credentials Flow" sections of the documentation.

<!-- gh-comment-id:860347390 --> @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_manager` and `auth_manager`. I think that info may be useful to others in the "Authorization Code Flow" and "Client Credentials Flow" sections of the documentation.
Author
Owner

@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_manager and client_credentials_manager parameters have been removed in the v3 branch, which contains changes for the upcoming version 3 release. We can't make this change in master because it would be a backwards incompatible change.

<!-- gh-comment-id:860348174 --> @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_manager` and `client_credentials_manager` parameters have been removed in the `v3` branch, which contains changes for the upcoming version 3 release. We can't make this change in `master` because it would be a backwards incompatible change.
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#409
No description provided.