Closed armpit6969 closed 3 years ago
Read the documentation. It's very clear about how to authorize your app.
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.
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.
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.
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.
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"