如何解决斑点认证错误
我正在使用 spotipy,但在设置时遇到问题。我从其他地方的答案中复制并粘贴了一段代码,但仍然出现错误。代码如下:
import spotipy
import spotipy.util as util
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy.oauth2 as oauth2
market = [ "AD","AR","AT","AU","BE","BG","BO","BR","CA","CH","CL","CO","CR","CY","CZ","DE","DK","DO","EC","EE","ES","FI","FR","GB","GR","GT","HK","HN","HU","ID","IE","IS","IT","JP","LI","LT","LU","LV","MC","MT","MX","MY","NI","NL","NO","NZ","PA","PE","PH","PL","PT","PY","SE","SG","SK","SV","TH","TR","TW","US","UY","VN" ]
credentials = oauth2.SpotifyClientCredentials(
client_id='1ccb087e16724c7d8cb3b21a9bdb7b55',client_secret="2d0faba9dd784e21a64d7b49db09e513")
token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)
track = "coldplay yellow"
res = spotify.search(track,type="track",market=market,limit=1)
print(res)
即使此代码适用于其他用户,我仍然收到以下错误消息:
Traceback (most recent call last):
File "c:/Users/Reesj/OneDrive/Documents/GitHub/python_bot/bot here/spotipytest.py",line 23,in <module>
res = spotify.search(track,limit=1)
File "C:\Users\Reesj\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py",line 547,in search
return self._get(
File "C:\Users\Reesj\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py",line 291,in _get
return self._internal_call("GET",url,payload,kwargs)
File "C:\Users\Reesj\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py",line 261,in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400,code:-1 - https://api.spotify.com/v1/search?q=coldplay+yellow&limit=1&offset=0&type=track&market=AD&market=AR&market=AT&market=AU&market=BE&market=BG&market=BO&market=BR&market=CA&market=CH&market=CL&market=CO&market=CR&market=CY&market=CZ&market=DE&market=DK&market=DO&market=EC&market=EE&market=ES&market=FI&market=FR&market=GB&market=GR&market=GT&market=HK&market=HN&market=HU&market=ID&market=IE&market=IS&market=IT&market=JP&market=LI&market=LT&market=LU&market=LV&market=MC&market=MT&market=MX&market=MY&market=NI&market=NL&market=NO&market=NZ&market=PA&market=PE&market=PH&market=PL&market=PT&market=PY&market=SE&market=SG&market=SK&market=SV&market=TH&market=TR&market=TW&market=US&market=UY&market=VN:
Only valid bearer authentication supported,reason: None
我是否遗漏了一些明显的东西?预先感谢您提供的任何帮助。
解决方法
您确定 client_id
和 client_secret
正确/仍然有效吗?您可以尝试从 Spotify Web Console 复制/粘贴有效令牌并将其用作 token
变量。如果可行,则问题在于您的应用程序设置(客户端 ID/机密等)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。