无法在 Spotipy 中获取新令牌

编程入门 行业动态 更新时间:2024-10-28 10:22:33
本文介绍了无法在 Spotipy 中获取新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

大约一个月前,我在图书馆玩,所有这些都按计划进行.现在我想再玩一次,但在尝试请求热门曲目时出现以下错误:

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 状态:400,代码:-1 -无法刷新令牌:代码:400 原因:错误请求,原因:{'授权':'基本Y2Y2NGFiNDY2ZDI0NDIyMzgzMjRhMjI0NTQxZDkzOGQ6MmJmMTQ5MTgxYmIxNDczZDg5MTAwOTEwYzkzOWRkZjU='}

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.

代码:

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/",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()

推荐答案

你能检查一下你的client_id和/或client_secret是否正确.

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

我已经用我的来运行它并且工作正常,但是,当我故意将 client_id 或 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).

这篇关于无法在 Spotipy 中获取新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 04:46:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   Spotipy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!