[GH-ISSUE #705] Error with recommendations(seed_genres) - HTTPError #419

Closed
opened 2026-02-27 23:22:31 +03:00 by kerem · 0 comments
Owner

Originally created by @samuelquant on GitHub (Jul 12, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/705

Describe the bug
While requesting to Spotify API recommendations(seed_genre=genre), the return is an HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co

I checked to Spotify Console (Get Recommendations Based on Seeds) and the right request should be: "https://api.spotify.com/v1/recommendations?seed_genres=techno"

Your code

genre='techno'

def get_recommendations(genre):
    recommendations = sp.recommendations(seed_genres=genre)
    return recommendations

print (get_recommendations(genre))

Expected behavior

{
  "tracks": [
    {
      "album": {
        "album_type": "SINGLE",
        "artists": [
          {
            "external_urls": {
              "spotify": "https://open.spotify.com/artist/0SfsnGyD8FpIN4U4WCkBZ5"
            },
            "href": "https://api.spotify.com/v1/artists/0SfsnGyD8FpIN4U4WCkBZ5",
            "id": "0SfsnGyD8FpIN4U4WCkBZ5",
            "name": "Armin van Buuren",
            "type": "artist",
            "uri": "spotify:artist:0SfsnGyD8FpIN4U4WCkBZ5"
          },
          {
            "external_urls": {
              "spotify": "https://open.spotify.com/artist/2r7POU2f5jV6x3k4vsNwrM"
            },
            "href": 

and so on

Output

HTTP Error for GET to https://api.spotify.com/v1/recommendations returned 400 due to invalid request
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _internal_call(self, method, url, payload, params)
    244 
--> 245             response.raise_for_status()
    246             results = response.json()

~/anaconda3/lib/python3.7/site-packages/requests/models.py in raise_for_status(self)
    942         if http_error_msg:
--> 943             raise HTTPError(http_error_msg, response=self)
    944 

HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co

During handling of the above exception, another exception occurred:

SpotifyException                          Traceback (most recent call last)
<ipython-input-15-633c1f3adc2e> in <module>
----> 1 print (get_recommendations(market, genre))

<ipython-input-9-acf54a711206> in get_recommendations(market, genre)
     17 
     18 def get_recommendations(market, genre):
---> 19     recommendations = sp.recommendations(seed_genres=genre)
     20     return recommendations

~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in recommendations(self, seed_artists, seed_genres, seed_tracks, limit, country, **kwargs)
   1650                 if param in kwargs:
   1651                     params[param] = kwargs[param]
-> 1652         return self._get("recommendations", **params)
   1653 
   1654     def recommendation_genre_seeds(self):

~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _get(self, url, args, payload, **kwargs)
    289             kwargs.update(args)
    290 
--> 291         return self._internal_call("GET", url, payload, kwargs)
    292 
    293     def _post(self, url, args=None, payload=None, **kwargs):

~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _internal_call(self, method, url, payload, params)
    264                 "%s:\n %s" % (response.url, msg),
    265                 reason=reason,
--> 266                 headers=response.headers,
    267             )
    268         except requests.exceptions.RetryError as retry_error:

SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co:
 invalid request, reason: None

Environment:

  • OS: Ubuntu 20.04.2 LTS
  • Python version 3.7.6
  • spotipy version 2.18.0
  • IDE jupyter notebook
Originally created by @samuelquant on GitHub (Jul 12, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/705 **Describe the bug** While requesting to Spotify API recommendations(seed_genre=genre), the return is an HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co I checked to Spotify Console (Get Recommendations Based on Seeds) and the right request should be: "https://api.spotify.com/v1/recommendations?seed_genres=techno" **Your code** ```python genre='techno' def get_recommendations(genre): recommendations = sp.recommendations(seed_genres=genre) return recommendations print (get_recommendations(genre)) ``` **Expected behavior** ```json { "tracks": [ { "album": { "album_type": "SINGLE", "artists": [ { "external_urls": { "spotify": "https://open.spotify.com/artist/0SfsnGyD8FpIN4U4WCkBZ5" }, "href": "https://api.spotify.com/v1/artists/0SfsnGyD8FpIN4U4WCkBZ5", "id": "0SfsnGyD8FpIN4U4WCkBZ5", "name": "Armin van Buuren", "type": "artist", "uri": "spotify:artist:0SfsnGyD8FpIN4U4WCkBZ5" }, { "external_urls": { "spotify": "https://open.spotify.com/artist/2r7POU2f5jV6x3k4vsNwrM" }, "href": ``` and so on **Output** ```python HTTP Error for GET to https://api.spotify.com/v1/recommendations returned 400 due to invalid request --------------------------------------------------------------------------- HTTPError Traceback (most recent call last) ~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _internal_call(self, method, url, payload, params) 244 --> 245 response.raise_for_status() 246 results = response.json() ~/anaconda3/lib/python3.7/site-packages/requests/models.py in raise_for_status(self) 942 if http_error_msg: --> 943 raise HTTPError(http_error_msg, response=self) 944 HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co During handling of the above exception, another exception occurred: SpotifyException Traceback (most recent call last) <ipython-input-15-633c1f3adc2e> in <module> ----> 1 print (get_recommendations(market, genre)) <ipython-input-9-acf54a711206> in get_recommendations(market, genre) 17 18 def get_recommendations(market, genre): ---> 19 recommendations = sp.recommendations(seed_genres=genre) 20 return recommendations ~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in recommendations(self, seed_artists, seed_genres, seed_tracks, limit, country, **kwargs) 1650 if param in kwargs: 1651 params[param] = kwargs[param] -> 1652 return self._get("recommendations", **params) 1653 1654 def recommendation_genre_seeds(self): ~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _get(self, url, args, payload, **kwargs) 289 kwargs.update(args) 290 --> 291 return self._internal_call("GET", url, payload, kwargs) 292 293 def _post(self, url, args=None, payload=None, **kwargs): ~/anaconda3/lib/python3.7/site-packages/spotipy/client.py in _internal_call(self, method, url, payload, params) 264 "%s:\n %s" % (response.url, msg), 265 reason=reason, --> 266 headers=response.headers, 267 ) 268 except requests.exceptions.RetryError as retry_error: SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?seed_genres=t%2Ce%2Cc%2Ch%2Cn%2Co: invalid request, reason: None ``` **Environment:** - OS: Ubuntu 20.04.2 LTS - Python version 3.7.6 - spotipy version 2.18.0 - IDE jupyter notebook
kerem 2026-02-27 23:22:31 +03:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#419
No description provided.