Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

400 Error from Get Recommendations

400 Error from Get Recommendations

Context

I use the recommendations api all the time. In a new code base, it fails and I can't figure out why. The code is the same. 

 

Error message

spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=20&target_valence=0.3:

 

Code snippets

recommendations = self.current_user.recommendations(limit=20, market='US', seed_artist='4NHQUGzhtTLFvgF5SZesLK',target_valence=.3)
 
Auth function
@app.route("/auth-callback")
def auth_callback():
   code = request.args.get("code")
   auth.get_access_token(code, as_dict=False)

try:
   if current_user.current_user()["display_name"] not in ['kornacle','Mashmia']:
   mp.track(current_user.current_user()['display_name'], 'Login Successful')
except:
   pass
login_user(current_user)
return redirect(url_for('login'))
Reply
2 Replies

Hey @mashmia - thanks for posting that code sample! 

I noticed that you have spelt the seed_artists parameter in the singular. Does it help if you change that to seed_artists, and pass it an array rather than a single string? Here is an example using the client credentials OAuth flow:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="client_id",
                                                           client_secret="client_secret"))

reccos = sp.recommendations(limit=20, market='US', seed_artists=['4NHQUGzhtTLFvgF5SZesLK'],target_valence=.3)
 

 

Thanks Josh. I updated to plural and still not having success. 

 

Somewhat different error message:

spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=20&target_valence=0.3:
 invalid request, reason: None

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random