Can't get new token in Spotipy

倖福魔咒の 提交于 2021-02-11 12:41:56

问题


About a month ago I was playing with the library and all of this worked as planned. Now I wanted to play with it again but I get the following error when trying to request the top tracks:

spotipy.exceptions.SpotifyException: http status: 400, code:-1 - Couldn't refresh token: code:400 reason:Bad Request, reason: {'Authorization': 'Basic Y2Y2NGFiNDY2ZDI0NDIyMzgzMjRhMjI0NTQxZDkzOGQ6MmJmMTQ5MTgxYmIxNDczZDg5MTAwOTEwYzkzOWRkZjU='}

I tried revoking the permission on my account in the hope it would prompt a new authorisation request but it didn't. It doesn't even show me the page where I have to give permission for acces to my account. How do I get a new token?

Note: I know that this isn't a safe way to use your secret or a good way to request scopes, but I am just playing with the library without any intent of ever publishing the code.

code:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from spotipy.oauth2 import SpotifyOAuth

cid= "cid_here"
secret= "secret_here"
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)

scopeFull = "ugc-image-upload user-read-recently-played user-top-read user-read-playback-position user-read-playback-state user-modify-playback-state user-read-currently-playing app-remote-control streaming playlist-modify-public playlist-modify-private playlist-read-private playlist-read-collaborative user-follow-modify user-follow-read user-library-modify user-library-read"
scopeRead = "user-read-recently-played user-top-read user-read-playback-position user-read-playback-state user-read-currently-playing playlist-modify-public playlist-read-private playlist-read-collaborative user-follow-read user-library-read "
scopePlay = "app-remote-control streaming "

ranges = ['short_term', 'medium_term', 'long_term']

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=cid, client_secret=secret,redirect_uri="https://google.com/",scope=scopeRead + scopePlay))

for sp_range in ['short_term', 'medium_term', 'long_term']:
    print("range:", sp_range)

    results = sp.current_user_top_tracks(time_range=sp_range, limit=10)

    for i, track in enumerate(results['items']):
        print("||", i + 1, track['name'], "-", track['popularity'])
    print()

回答1:


Can you check to see if you have the correct client_id and / or client_secret.

I have run this using mine and works ok, however, when i deliberately have the client_id or client_secret wrong, it throws the exact same error.

maybe it is caching wrong credentials? an easy way to uncache is to change the scope (i.e. remove one, then try it, you can add back after).



来源:https://stackoverflow.com/questions/65112476/cant-get-new-token-in-spotipy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!