[GH-ISSUE #306] Error with tokens #175

Closed
opened 2026-02-27 23:21:13 +03:00 by kerem · 4 comments
Owner

Originally created by @theerfan on GitHub (Jul 3, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/306

Hi, I'm trying to manually add some albums to my saved ones, but I keep getting this error with a link that leads me to a page with some JSON code which says "no token provided", I think I have read the doc carefully enough, but I'm still unable to figure out the problem.
[I have already done the first authorization thing where you have to give the program a link before starting everything.]

import spotipy
import spotipy.util

from spotipy.oauth2 import SpotifyClientCredentials

username = //omitted
clientID = //omitted
access = 'user-library-modify'
clientSecret =  //omitted
redirectURL = 'http://localhost/'
token = spotipy.util.prompt_for_user_token(username =username, scope= access, client_id = clientID,
                                 client_secret = clientSecret, redirect_uri=redirectURL)
client_manager = SpotifyClientCredentials(clientID, clientSecret)
spotify = spotipy.Spotify(auth=token, client_credentials_manager= client_manager)

added_albums = //omitted #But a list of valid album ids that I sucessfully retrieved from spotify nevertheless

spotify.current_user_saved_albums_add(added_albums)

Thanks in advance.

Originally created by @theerfan on GitHub (Jul 3, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/306 Hi, I'm trying to manually add some albums to my saved ones, but I keep getting this error with a link that leads me to a page with some JSON code which says "no token provided", I think I have read the doc carefully enough, but I'm still unable to figure out the problem. [I have already done the first authorization thing where you have to give the program a link before starting everything.] ``` import spotipy import spotipy.util from spotipy.oauth2 import SpotifyClientCredentials username = //omitted clientID = //omitted access = 'user-library-modify' clientSecret = //omitted redirectURL = 'http://localhost/' token = spotipy.util.prompt_for_user_token(username =username, scope= access, client_id = clientID, client_secret = clientSecret, redirect_uri=redirectURL) client_manager = SpotifyClientCredentials(clientID, clientSecret) spotify = spotipy.Spotify(auth=token, client_credentials_manager= client_manager) added_albums = //omitted #But a list of valid album ids that I sucessfully retrieved from spotify nevertheless spotify.current_user_saved_albums_add(added_albums) ``` Thanks in advance.
kerem closed this issue 2026-02-27 23:21:13 +03:00
Author
Owner

@brobotic commented on GitHub (Jul 4, 2018):

What version of spotipy & python are you using?

Having trouble reproducing this with your code. I created a new test app using your settings (same scope and redirect_uri) and successfully added an album to my saved music.

Still new myself, but the only thing that seems off to me is the line where you define your token. The documentation states that prompt_for_user_token's first argument is simply your username and not 'username=username'. Perhaps try changing that line to that? Like this:

token = spotipy.util.prompt_for_user_token(username, scope=access, client_id=clientID, client_secret=clientSecret, redirect_uri=redirectURL)

<!-- gh-comment-id:402333892 --> @brobotic commented on GitHub (Jul 4, 2018): What version of spotipy & python are you using? Having trouble reproducing this with your code. I created a new test app using your settings (same scope and redirect_uri) and successfully added an album to my saved music. Still new myself, but the only thing that seems off to me is the line where you define your token. The documentation states that prompt_for_user_token's first argument is simply your username and not 'username=username'. Perhaps try changing that line to that? Like this: `token = spotipy.util.prompt_for_user_token(username, scope=access, client_id=clientID, client_secret=clientSecret, redirect_uri=redirectURL)`
Author
Owner

@theerfan commented on GitHub (Jul 5, 2018):

Python 3.6.5 and Spotipy 2.4.4
Changed the line but I'm still getting the same link as before.

P.S: Could the fact that I have to use a VPN (and am while running this code) in order to use spotify have something to do with this?

P.S.2: It's really weird, I can retrieve my saved track (by changing the scope of course) easily, but only when I try to modify something, this happens.

<!-- gh-comment-id:402630794 --> @theerfan commented on GitHub (Jul 5, 2018): Python 3.6.5 and Spotipy 2.4.4 Changed the line but I'm still getting the same link as before. P.S: Could the fact that I have to use a VPN (and am while running this code) in order to use spotify have something to do with this? P.S.2: It's really weird, I can retrieve my saved track (by changing the scope of course) easily, but only when I try to modify something, this happens.
Author
Owner

@brobotic commented on GitHub (Jul 7, 2018):

Very odd indeed.

The VPN could be a factor, but I guess that would depend on the type of VPN and its configuration. spotipy is just opening https://accounts.spotify.com/authorize (along with some additional parameters in the URL) in your browser, and then their service will redirect you to whatever redirect_uri you set in your app configuration in the Developer portal on Spotify's website. Since you are using http://localhost/, I'm not terribly convinced that the VPN would interfere. With that said, hard to say if that's the issue.

Wish I could be of more help but I don't have any sort of VPN to test with / don't know which service you are using for that.

Edit: for the sake of testing, what if you changed the redirect_uri in your app's settings on Spotify's site? Something with a different port. Like: http://localhost:8888/callback

<!-- gh-comment-id:403183262 --> @brobotic commented on GitHub (Jul 7, 2018): Very odd indeed. The VPN could be a factor, but I guess that would depend on the type of VPN and its configuration. spotipy is just opening https://accounts.spotify.com/authorize (along with some additional parameters in the URL) in your browser, and then their service will redirect you to whatever redirect_uri you set in your app configuration in the Developer portal on Spotify's website. Since you are using http://localhost/, I'm not terribly convinced that the VPN would interfere. With that said, hard to say if that's the issue. Wish I could be of more help but I don't have any sort of VPN to test with / don't know which service you are using for that. Edit: for the sake of testing, what if you changed the redirect_uri in your app's settings on Spotify's site? Something with a different port. Like: http://localhost:8888/callback
Author
Owner

@stephanebruckert commented on GitHub (Jan 13, 2020):

@theerfan you are currently using both authentication flows at the same time. To use the token and access your spotify profile data, you need to use the token while getting rid of the client_credentials_manager.

So change this:

client_manager = SpotifyClientCredentials(clientID, clientSecret)
spotify = spotipy.Spotify(auth=token, client_credentials_manager= client_manager) 

to:

spotify = spotipy.Spotify(auth=token) 

Read about it here https://spotipy.readthedocs.io/en/2.6.1/#authorization-code-flow

<!-- gh-comment-id:573900507 --> @stephanebruckert commented on GitHub (Jan 13, 2020): @theerfan you are currently using both authentication flows at the same time. To use the token and access your spotify profile data, you need to use the token while getting rid of the `client_credentials_manager`. So change this: ``` client_manager = SpotifyClientCredentials(clientID, clientSecret) spotify = spotipy.Spotify(auth=token, client_credentials_manager= client_manager) ``` to: spotify = spotipy.Spotify(auth=token) Read about it here https://spotipy.readthedocs.io/en/2.6.1/#authorization-code-flow
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#175
No description provided.