[GH-ISSUE #504] Error 401: No token provided #302

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

Originally created by @ElementO2512 on GitHub (May 29, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/504

Hey,
Basically when ever I try to run this script I get a 'No token provided' error.
Heres my code:

`import spotipy
#import python-util
import os
from spotipy.oauth2 import SpotifyClientCredentials

os.environ["SPOTIPY_CLIENT_ID"] = "(my client id)"
os.environ["SPOTIPY_CLIENT_SECRET"] = "(my client secret)"
client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())

spotipy.prompt_for_user_token(username='', scope='', client_id='(my client id)', client_secret='(my client secret)', redirect_uri='http://localhost:9090')

spp = spotipy.Spotify()

songinfo = spp.current_playback(market=None)
print('songinfo')`

What code do I need to add to make this work?

Originally created by @ElementO2512 on GitHub (May 29, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/504 Hey, Basically when ever I try to run this script I get a 'No token provided' error. Heres my code: `import spotipy #import python-util import os from spotipy.oauth2 import SpotifyClientCredentials os.environ["SPOTIPY_CLIENT_ID"] = "(my client id)" os.environ["SPOTIPY_CLIENT_SECRET"] = "(my client secret)" client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) spotipy.prompt_for_user_token(username='', scope='', client_id='(my client id)', client_secret='(my client secret)', redirect_uri='http://localhost:9090') spp = spotipy.Spotify() songinfo = spp.current_playback(market=None) print('songinfo')` What code do I need to add to make this work?
kerem 2026-02-27 23:21:53 +03:00
Author
Owner

@anpanval commented on GitHub (May 29, 2020):

Hello,
I have the same issue today, everything worked well yesterday with the same code.

<!-- gh-comment-id:635916589 --> @anpanval commented on GitHub (May 29, 2020): Hello, I have the same issue today, everything worked well yesterday with the same code.
Author
Owner

@ysinjab commented on GitHub (May 29, 2020):

Hi, you are using spp = spotipy.Spotify() without passing any of: auth, client_credentials_manager, oauth_manager, auth_manager.

auth is the token.
auth_manager is either client_credentials_manager or oauth_manager

<!-- gh-comment-id:636016003 --> @ysinjab commented on GitHub (May 29, 2020): Hi, you are using spp = spotipy.Spotify() without passing any of: auth, client_credentials_manager, oauth_manager, auth_manager. auth is the token. auth_manager is either client_credentials_manager or oauth_manager
Author
Owner

@ElementO2512 commented on GitHub (May 30, 2020):

Hey Thanks for the Answer
Realised Im really retarded and already had the right thing but wasn't using it
My code now looks like this:

`
import spotipy
import os
from spotipy.oauth2 import SpotifyClientCredentials

os.environ["SPOTIPY_CLIENT_ID"] = "(my client id)"
os.environ["SPOTIPY_CLIENT_SECRET"] = "(my client secret)"
client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())

spotipy.prompt_for_user_token(username='', scope='user-read-currently-playing', client_id='(my client id)', client_secret='(my client secret)', redirect_uri='http://localhost:9090')

songinfo = sp.current_playback(market=None)
print('songinfo')
`

I'm now getting a 404 Invalid username error. I'm guessing this is because username='' is blank. What should I put here?

<!-- gh-comment-id:636280726 --> @ElementO2512 commented on GitHub (May 30, 2020): Hey Thanks for the Answer Realised Im really retarded and already had the right thing but wasn't using it My code now looks like this: ` import spotipy import os from spotipy.oauth2 import SpotifyClientCredentials os.environ["SPOTIPY_CLIENT_ID"] = "(my client id)" os.environ["SPOTIPY_CLIENT_SECRET"] = "(my client secret)" client_credentials_manager = SpotifyClientCredentials() sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) spotipy.prompt_for_user_token(username='', scope='user-read-currently-playing', client_id='(my client id)', client_secret='(my client secret)', redirect_uri='http://localhost:9090') songinfo = sp.current_playback(market=None) print('songinfo') ` I'm now getting a 404 Invalid username error. I'm guessing this is because `username=''` is blank. What should I put here?
Author
Owner

@stephanebruckert commented on GitHub (Jun 14, 2020):

We just deprecated prompt_for_user_token, check out this example https://github.com/plamere/spotipy#with-user-authentication, this is all you need:

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
<!-- gh-comment-id:643794807 --> @stephanebruckert commented on GitHub (Jun 14, 2020): We just deprecated `prompt_for_user_token`, check out this example https://github.com/plamere/spotipy#with-user-authentication, this is all you need: sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
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#302
No description provided.