Getting 404 error when using Spotify's recommendation endpoint

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?

It seems that the error stems from providing seed_tracks=None while also having an unused list of track_seeds. The Spotify API mandates that at least one valid seed parameter must be included in the request. You should modify your call to client.recommendations(seed_tracks=track_seeds, seed_genres=['rock'], limit=15), or simply eliminate the track_seeds variable if you plan to rely solely on genre-based recommendations. I encountered a similar issue earlier with misleading 404 errors, which were due to parameter validation rather than a problem with the endpoint itself. Also, ensure that the track IDs in the track_seeds list are valid Spotify track IDs if you choose to use them.