[GH-ISSUE #290] recommendation invalid request #162

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

Originally created by @Mariog75 on GitHub (May 16, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/290

when making a recommendations request such as:
recommend = sp.recommendations(target_energy = 0.5)

I get the error:
Traceback (most recent call last):
File "script.py", line 62, in
recommend = sp.recommendations(target_energy = 0.5)
File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 804, in recommendations
return self._get('recommendations', **params)
File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 146, in _get
return self._internal_call('GET', url, payload, kwargs)
File "/usr/local/lib/python2.7/dist-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?target_energy=0.5&limit=20:
invalid request

any particular reason why this is giving an invalid request?

Originally created by @Mariog75 on GitHub (May 16, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/290 when making a recommendations request such as: recommend = sp.recommendations(target_energy = 0.5) I get the error: Traceback (most recent call last): File "script.py", line 62, in <module> recommend = sp.recommendations(target_energy = 0.5) File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 804, in recommendations return self._get('recommendations', **params) File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 146, in _get return self._internal_call('GET', url, payload, kwargs) File "/usr/local/lib/python2.7/dist-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?target_energy=0.5&limit=20: invalid request any particular reason why this is giving an invalid request?
kerem 2026-02-27 23:21:08 +03:00
Author
Owner

@smyrbdr commented on GitHub (May 30, 2018):

Looks like you didn't get token authorization for the session. The error message says "no token provided"

<!-- gh-comment-id:392996778 --> @smyrbdr commented on GitHub (May 30, 2018): Looks like you didn't get token authorization for the session. The error message says "no token provided"
Author
Owner

@JessicaMartini212887 commented on GitHub (Jun 23, 2018):

I think that is because you have to put at least one of these parameters in the request:

  • seed artists;
  • seed genres;
  • seed tracks.
    Target_energy isn't sufficient.
<!-- gh-comment-id:399616161 --> @JessicaMartini212887 commented on GitHub (Jun 23, 2018): I think that is because you have to put at least one of these parameters in the request: - seed artists; - seed genres; - seed tracks. Target_energy isn't sufficient.
Author
Owner

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

@JessicaMartini212887 is correct, we need to update the doc accordingly

<!-- gh-comment-id:573407942 --> @stephanebruckert commented on GitHub (Jan 12, 2020): @JessicaMartini212887 is correct, we need to update the doc accordingly
Author
Owner

@AkiMosi commented on GitHub (Apr 13, 2020):

I think that is because you have to put at least one of these parameters in the request:

  • seed artists;
  • seed genres;
  • seed tracks.
    Target_energy isn't sufficient.

At least one is enough? I tried just by giving the seed track. And I still got an error stating 'invalid request'. Or should we give more than one track_id?

<!-- gh-comment-id:612899140 --> @AkiMosi commented on GitHub (Apr 13, 2020): > I think that is because you have to put at least one of these parameters in the request: > > * seed artists; > * seed genres; > * seed tracks. > Target_energy isn't sufficient. At least one is enough? I tried just by giving the seed track. And I still got an error stating 'invalid request'. Or should we give more than one track_id?
Author
Owner

@stephanebruckert commented on GitHub (Apr 13, 2020):

@AkiMosi can you please share the exact request being made + full stacktrace/error

And does that same request work if you try it on this web UI? https://developer.spotify.com/console/get-recommendations/

<!-- gh-comment-id:612913496 --> @stephanebruckert commented on GitHub (Apr 13, 2020): @AkiMosi can you please share the exact request being made + full stacktrace/error And does that same request work if you try it on this web UI? https://developer.spotify.com/console/get-recommendations/
Author
Owner

@AkiMosi commented on GitHub (Apr 13, 2020):

@AkiMosi can you please share the exact request being made + full stacktrace/error

And does that same request work if you try it on this web UI? https://developer.spotify.com/console/get-recommendations/

I found what I did wrong with the code, by going through issue #305
I did not give it as a list, I just gave the id as a string.

Thanks for your quick response, and it would be great if you add a little code snippet in the examples of the documentation.

<!-- gh-comment-id:612917449 --> @AkiMosi commented on GitHub (Apr 13, 2020): > @AkiMosi can you please share the exact request being made + full stacktrace/error > > And does that same request work if you try it on this web UI? https://developer.spotify.com/console/get-recommendations/ I found what I did wrong with the code, by going through issue #305 I did not give it as a list, I just gave the id as a string. Thanks for your quick response, and it would be great if you add a little code snippet in the examples of the documentation.
Author
Owner

@stephanebruckert commented on GitHub (Apr 13, 2020):

Cool! Please feel free to open a PR to add an example

Just for reference, since this is about types I'm linking this issue https://github.com/plamere/spotipy/issues/439

<!-- gh-comment-id:612918741 --> @stephanebruckert commented on GitHub (Apr 13, 2020): Cool! Please feel free to open a PR to add an example Just for reference, since this is about types I'm linking this issue https://github.com/plamere/spotipy/issues/439
Author
Owner

@mikedesu commented on GitHub (Dec 5, 2020):

When attempting to pull down recommendations, I am getting the following error:

HTTP Error for GET to https://api.spotify.com/v1/recommendations returned 400 due to invalid request
Traceback (most recent call last):
  File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, 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_artists=Katy+Perry

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bug_recommendations.py", line 12, in <module>
    main()
  File "bug_recommendations.py", line 9, in main
    results = sp.recommendations(seed_artists=artist_list)
  File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 1597, in recommendations
    return self._get("recommendations", **params)
  File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/darkmage/.local/lib/python3.8/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/recommendations?limit=20&seed_artists=Katy+Perry:
 invalid request, reason: None

I followed the API documentation, here is the script generating the error:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

def main():
    sp = spotipy.Spotify( auth_manager=SpotifyClientCredentials( client_id="CLIENT_ID", client_secret="CLIENT_SECRET"))
    result_amount = 5
    artist_list = [ "Katy Perry" ]
    results = sp.recommendations(seed_artists=artist_list)

if __name__ == "__main__":
    main()
<!-- gh-comment-id:739422426 --> @mikedesu commented on GitHub (Dec 5, 2020): When attempting to pull down recommendations, I am getting the following error: ``` HTTP Error for GET to https://api.spotify.com/v1/recommendations returned 400 due to invalid request Traceback (most recent call last): File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 940, 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_artists=Katy+Perry During handling of the above exception, another exception occurred: Traceback (most recent call last): File "bug_recommendations.py", line 12, in <module> main() File "bug_recommendations.py", line 9, in main results = sp.recommendations(seed_artists=artist_list) File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 1597, in recommendations return self._get("recommendations", **params) File "/home/darkmage/.local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get return self._internal_call("GET", url, payload, kwargs) File "/home/darkmage/.local/lib/python3.8/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/recommendations?limit=20&seed_artists=Katy+Perry: invalid request, reason: None ``` I followed the API documentation, here is the script generating the error: ``` import spotipy from spotipy.oauth2 import SpotifyClientCredentials def main(): sp = spotipy.Spotify( auth_manager=SpotifyClientCredentials( client_id="CLIENT_ID", client_secret="CLIENT_SECRET")) result_amount = 5 artist_list = [ "Katy Perry" ] results = sp.recommendations(seed_artists=artist_list) if __name__ == "__main__": main() ```
Author
Owner

@stephanebruckert commented on GitHub (Dec 5, 2020):

@mikedesu see https://github.com/plamere/spotipy/issues/290#issuecomment-399616161

<!-- gh-comment-id:739432158 --> @stephanebruckert commented on GitHub (Dec 5, 2020): @mikedesu see https://github.com/plamere/spotipy/issues/290#issuecomment-399616161
Author
Owner

@mikedesu commented on GitHub (Dec 6, 2020):

@mikedesu see #290 (comment)

My apologies, the issue isn't answered of in that comment, hence the post.

However, I realize the problem now. The artist list must be comprised of artist IDs, not artist names.

Thanks.

<!-- gh-comment-id:739438245 --> @mikedesu commented on GitHub (Dec 6, 2020): > @mikedesu see [#290 (comment)](https://github.com/plamere/spotipy/issues/290#issuecomment-399616161) My apologies, the issue isn't answered of in that comment, hence the post. However, I realize the problem now. The artist list must be comprised of artist IDs, not artist names. Thanks.
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#162
No description provided.