Spotify Web API Error 403 - Client Scope Insufficient for Playlist Creation

I’m getting a 403 error when trying to create playlists using the Spotify API. The weird thing is my code was working fine earlier today. I just stepped away for a few minutes and when I came back it started failing.

user_id = '8mn6xkqweah21rd3pjx9y5nop'
client_app_id = 'b85eacbd28574df4962cef178e765c54'
client_app_secret = '{My Secret Key}'
redirect_url = 'http://localhost:80'

# Initialize Spotify client with OAuth
spotify_client = spotipy.Spotify(auth_manager=SpotifyOAuth(
    client_id=client_app_id,
    client_secret=client_app_secret,
    redirect_uri=redirect_url,
    scope="user-library-read"
))

# Retrieve access token
token_info = spotify_client.auth_manager.get_access_token(as_dict=False)

def generate_recommendation_playlist(content_type, seed_id, list_name='My Recommendations'):
    client = spotipy.Spotify(auth=token_info, auth_manager=SpotifyOAuth(client_id=client_app_id,
                                                                       client_secret=client_app_secret,
                                                                       redirect_uri=redirect_url,
                                                                       scope='playlist-modify-public'))
    
    # Fetch recommendations based on seed
    if content_type == "song":
        recommendations = client.recommendations(seed_tracks=[seed_id], limit=10)['tracks']
    elif content_type == "musician":
        recommendations = client.recommendations(seed_artists=[seed_id], limit=10)['tracks']
    
    # Extract URIs from recommendations
    song_uris = [song['uri'] for song in recommendations]
    
    # Create new playlist
    new_playlist = client.user_playlist_create(user=user_id, name=list_name, public=False)
    
    # Add songs to playlist
    client.playlist_add_items(playlist_id=new_playlist['id'], items=song_uris)
    
    return new_playlist

# This line triggers the error
my_playlist = generate_recommendation_playlist("musician", "4rbE8MKSOBhgHhGiUVLmX")

The error says insufficient client scope but I have the right scopes set. My other function for getting user’s top tracks works fine with different scopes. I’ve tried recreating the app in Spotify dashboard and using fresh code but nothing works. What am I missing here?

Your dual auth setup is causing this. You’re creating two SpotifyOAuth instances with different scopes, which messes up the token states. First you initialize spotify_client with “user-library-read”, then try creating another client with “playlist-modify-public” - the auth manager doesn’t know which token to use. Had the same issue last month and it drove me crazy for hours. Fix: combine your scopes upfront. Set your initial SpotifyOAuth with “user-library-read playlist-modify-public” and reuse that same auth manager everywhere instead of creating a new one in the function. Delete any .cache files before testing too.

check your .cache file - old tokens sometimes get stuck there even after changing scopes. delete it and re-authenticate completely. also, your redirect_url should probably be http://localhost:8080 instead of port 80. that might be causing auth issues too.

Your token from the first auth manager doesn’t have playlist creation permissions. When you call get_access_token() on that initial spotify_client, you’re getting a token that’s only scoped for “user-library-read”. The new Spotify client instance needs a token with playlist modification rights instead. I ran into this exact problem building my own playlist generator last year. The token matters here, not just which auth manager you use later. Either request all the scopes you need upfront, or split your auth flows completely - let the second SpotifyOAuth handle its own token instead of reusing the first one.

you nailed it! two auths will mess things up. just combine the scopes into one like “user-library-read playlist-modify-public” when you set up the first spotify_client. keep it simple and it’ll work!