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?
Looks like you didn't get token authorization for the session. The error message says "no token provided"
I think that is because you have to put at least one of these parameters in the request:
@JessicaMartini212887 is correct, we need to update the doc accordingly
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?
@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 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.
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
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()
@mikedesu see https://github.com/plamere/spotipy/issues/290#issuecomment-399616161
@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.