【发布时间】:2021-06-02 14:43:32
【问题描述】:
我正在使用 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, type="track", market=market, 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
我是否遗漏了一些明显的东西?提前感谢您提供的任何帮助。
【问题讨论】: