I’m trying to build a music app that gets my favorite tracks from Spotify and then finds similar songs using their recommendation system. The part where I fetch my top songs works fine, but I keep getting a 404 error when I try to get recommended tracks.
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# API setup
app_id = 'my_client_id'
app_secret = 'my_client_secret'
redirect_url = 'http://localhost:3000/callback'
permissions = "user-top-read playlist-modify-public"
# Target playlist
playlist_id = '1Ab2Cd3Ef4Gh5Ij6Kl7Mn8'
# Setup Spotify client
client = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=app_id,
client_secret=app_secret,
redirect_uri=redirect_url,
scope=permissions
))
def get_suggestions():
track_seeds = ['1Aa2Bb3Cc4Dd5Ee6Ff7Gg8','9Hh0Ii1Jj2Kk3Ll4Mm5Nn6']
suggestions = client.recommendations(seed_tracks=None, seed_genres=['rock'], seed_artists=None, limit=15)
suggestion_ids = [song['id'] for song in suggestions['tracks']]
return suggestion_ids
get_suggestions()
The error says the recommendations endpoint returns 404 but I can’t figure out what’s wrong with my request. Has anyone dealt with this before?