Spotipy: Error 401: No token provided

Created on 29 May 2020  路  4Comments  路  Source: plamere/spotipy

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?

documentation

Most helpful comment

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

All 4 comments

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

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

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?

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))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

DylanMeeus picture DylanMeeus  路  4Comments

AnySomebody1 picture AnySomebody1  路  3Comments

StefanRickli picture StefanRickli  路  3Comments

danielgwilson picture danielgwilson  路  4Comments

CMoore97 picture CMoore97  路  3Comments