Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recommendation invalid request #290

Closed
Mariog75 opened this issue May 16, 2018 · 10 comments
Closed

recommendation invalid request #290

Mariog75 opened this issue May 16, 2018 · 10 comments

Comments

@Mariog75
Copy link

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?

@Mariog75 Mariog75 changed the title recommendatiosn invalid request recommendation invalid request May 16, 2018
@smyrbdr
Copy link

smyrbdr commented May 30, 2018

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

@JessicaMartini212887
Copy link

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.

@stephanebruckert
Copy link
Member

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

@AkiMosi
Copy link

AkiMosi commented 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?

@stephanebruckert
Copy link
Member

stephanebruckert commented 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/

@AkiMosi
Copy link

AkiMosi commented 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.

@stephanebruckert
Copy link
Member

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 #439

@mikedesu
Copy link

mikedesu commented 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()

@stephanebruckert
Copy link
Member

@mikedesu see #290 (comment)

@mikedesu
Copy link

mikedesu commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants