I'm currently writing an application that takes in a user prompt and their listening data and creates a playlist for them. I also analyse the prompt with a bart model to identify which genres of music are most suitable.
In trying to get the list of genres that spotify uses with the Spotipy library's recommendation_genre_seeds() function, I've recently (over the past week) run into an exception that I did not previously get. The last time I wrote code for this application was around 3 - 4 weeks ago, when it ran smoothly.
I did some debugging in jupyter notebook. Given that I've initialised my spotipy model:
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"))
Here is the snippet of code that throws the exception.
sp.recommendation_genre_seeds()
The exception is as follows.
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
Is there an issue with the spotify api that has caused Spotipy to crash like this? I've tried to look it up, I got some inkling of this issue but I just wanted to confirm that and also see if there's any workaround for this error.
Please let me know if there is any issue in my question as it is my first time posting on StackOverflow, thank you!
The documentation has now been updated, and the /recommendations/available-genre-seeds
endpoint is also marked as deprecated.
You'll be getting an error as the recommendation_genre_seeds()
function uses this endpoint to fetch the data.