我目前正在编写一个应用程序,它接受用户提示和他们的收听数据,并为他们创建一个播放列表。我还使用巴特模型分析提示,以确定哪种音乐流派最合适。
在尝试使用 Spotipy 库的recommendation_genre_seeds()函数获取Spotify使用的流派列表时,我最近(在过去的一周)遇到了一个我以前没有遇到过的异常。我上次为这个应用程序编写代码是在大约 3 - 4 周前,当时它运行顺利。
我在jupyter笔记本上做了一些调试。鉴于我已经初始化了我的斑点模型:
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri=REDIRECT_URI,
scope="playlist-modify-private playlist-modify-public user-top-read user-read-recently-played user-library-read user-follow-read"))
这是引发异常的代码片段。
sp.recommendation_genre_seeds()
例外情况如下。
HTTP Error for GET to https://api.spotify.com/v1/recommendations/available-genre-seeds with Params: {} returned 404 due to None
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
~\anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
274
--> 275 response.raise_for_status()
276 results = response.json()
~\anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
1022
HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/recommendations/available-genre-seeds
During handling of the above exception, another exception occurred:
SpotifyException Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_19528\936109238.py in <module>
----> 1 sp.recommendation_genre_seeds()
~\anaconda3\lib\site-packages\spotipy\client.py in recommendation_genre_seeds(self)
1731 """ Get a list of genres available for the recommendations function.
1732 """
-> 1733 return self._get("recommendations/available-genre-seeds")
1734
1735 def audio_analysis(self, track_id):
~\anaconda3\lib\site-packages\spotipy\client.py in _get(self, url, args, payload, **kwargs)
325 kwargs.update(args)
326
--> 327 return self._internal_call("GET", url, payload, kwargs)
328
329 def _post(self, url, args=None, payload=None, **kwargs):
~\anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
295 )
296
--> 297 raise SpotifyException(
298 response.status_code,
299 -1,
SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/recommendations/available-genre-seeds:
None, reason: None
spotify api 是否存在问题导致 Spotipy 像这样崩溃?我尝试查找它,我对这个问题有了一些了解,但我只是想确认一下,并看看是否有任何解决此错误的方法。
如果我的问题有任何问题,请告诉我,因为这是我第一次在 StackOverflow 上发帖,谢谢!