[GH-ISSUE #305] Error with Recommendations #174

Closed
opened 2026-02-27 23:21:12 +03:00 by kerem · 2 comments
Owner

Originally created by @stant1er on GitHub (Jun 28, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/305

When using the recommendations request like this:
recommendations = spotify.recommendations(seed_tracks = track['id'])

I end up with this error:
Traceback (most recent call last):
File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 119, in _internal_call
r.raise_for_status()
File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 939, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?limit=20&seed_tracks=1%2Cp%2C8%2C0%2CL%2Cd%2Cx%2CR%2CV%2C7%2C4%2CU%2CK%2Cv%2CL%2C8%2Cg%2Cn%2CD%2C7%2Ck%2Cy

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "spotifytest.py", line 13, in
recommendations = spotify.recommendations(seed_tracks = track['id'])
File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 804, in recommendations
return self._get('recommendations', **params)
File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 146, in _get
return self._internal_call('GET', url, payload, kwargs)
File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 124, in _internal_call
headers=r.headers)
spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=20&seed_tracks=1%2Cp%2C8%2C0%2CL%2Cd%2Cx%2CR%2CV%2C7%2C4%2CU%2CK%2Cv%2CL%2C8%2Cg%2Cn%2CD%2C7%2Ck%2Cy:
invalid request

Does anyone know why I'm getting this error?

Originally created by @stant1er on GitHub (Jun 28, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/305 When using the recommendations request like this: recommendations = spotify.recommendations(seed_tracks = track['id']) I end up with this error: Traceback (most recent call last): File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 119, in _internal_call r.raise_for_status() File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\models.py", line 939, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?limit=20&seed_tracks=1%2Cp%2C8%2C0%2CL%2Cd%2Cx%2CR%2CV%2C7%2C4%2CU%2CK%2Cv%2CL%2C8%2Cg%2Cn%2CD%2C7%2Ck%2Cy During handling of the above exception, another exception occurred: Traceback (most recent call last): File "spotifytest.py", line 13, in <module> recommendations = spotify.recommendations(seed_tracks = track['id']) File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 804, in recommendations return self._get('recommendations', **params) File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 146, in _get return self._internal_call('GET', url, payload, kwargs) File "AppData\Local\Programs\Python\Python36-32\lib\site-packages\spotipy\client.py", line 124, in _internal_call headers=r.headers) spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=20&seed_tracks=1%2Cp%2C8%2C0%2CL%2Cd%2Cx%2CR%2CV%2C7%2C4%2CU%2CK%2Cv%2CL%2C8%2Cg%2Cn%2CD%2C7%2Ck%2Cy: invalid request Does anyone know why I'm getting this error?
kerem closed this issue 2026-02-27 23:21:12 +03:00
Author
Owner

@brobotic commented on GitHub (Jul 4, 2018):

Sounds like track['id'] is just a string variable and not a list that contains URI strings. Even if it is just one track/artist/genre, it should be in a list.

You will want to make sure your seed track(s) are in a list, like so:
track = ['spotify:track:42GP0xKtkolBnmqQRvSllO']

And make sure that track is not just a string in a variable that contains the URI:

track = 'spotify:track:42GP0xKtkolBnmqQRvSllO'

I get the same error you do when using just a string in a variable for the seed track. Works fine when it's in a list.

<!-- gh-comment-id:402551493 --> @brobotic commented on GitHub (Jul 4, 2018): Sounds like track['id'] is just a string variable and not a list that contains URI strings. Even if it is just one track/artist/genre, it should be in a list. You will want to make sure your seed track(s) are in a list, like so: track = ['spotify:track:42GP0xKtkolBnmqQRvSllO'] And make sure that track is not just a string in a variable that contains the URI: track = 'spotify:track:42GP0xKtkolBnmqQRvSllO' I get the same error you do when using just a string in a variable for the seed track. Works fine when it's in a list.
Author
Owner

@stephanebruckert commented on GitHub (Jan 12, 2020):

Hi @Stantl3r and thanks @brobotic, yes the doc says that seed_tracks should be a list.

seed_tracks - a list of artist IDs, URIs or URLs

<!-- gh-comment-id:573407720 --> @stephanebruckert commented on GitHub (Jan 12, 2020): Hi @Stantl3r and thanks @brobotic, yes the doc says that `seed_tracks` should be a list. > seed_tracks - a list of artist IDs, URIs or URLs
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#174
No description provided.