Alessandro Minervini
Alessandro Minervini

Reputation: 123

Can't skip to next song on Spotify API (via Spotipy)

I'm implementing a simple application with spotipy.
I want to skip the next track, but I've got this error in output:

spotipy.client.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/next: Not available for the current user

My code:

import os
import spotipy
import spotipy.util as util
from json.decoder import JSONDecodeError


# Set data client, redirect URL and username
username = 'xxxx'
client_id = 'xxxxxxxx'
client_secret = 'xxxxxxxx'
redirect_uri = 'https://www.xxxxx.it/'
scope = 'user-modify-playback-state'


# Erase cache and prompt for user permission
try:
    token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
except (AttributeError, JSONDecodeError):
    os.remove(f".cache-{username}")
    token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)


# Configure Spotify
sp = spotipy.Spotify(auth=token)
current = sp.next_track()

Upvotes: 2

Views: 2578

Answers (1)

Maor Refaeli
Maor Refaeli

Reputation: 2537

You can skip songs only for premium users.
Check these articles:

FYI, Error 403 is authorization error:

The HTTP 403 Forbidden client error status response code indicates that the server understood the request but refuses to authorize it.

This status is similar to 401, but in this case, re-authenticating will make no difference. The access is permanently forbidden and tied to the application logic, such as insufficient rights to a resource.

Upvotes: 2

Related Questions