I'm being thrown the following exception when trying to add a track to a playlist via user_playlist_add_tracks using a track URI.
Code sample;
import spotipy
import spotipy.util as util
username = 'my-username'
client_id ='my-spotify-client-id'
client_secret ='my-spotify-client-secret-id'
scope = 'playlist-modify-private, user-read-recently-played, playlist-modify-public'
token = util.prompt_for_user_token(username, scope,
my-client-id,
my-spotify-client-secret,
'http://localhost/')
if token:
sp = spotipy.Spotify(auth=token)
song = 'spotify:track:6b2oQwSGFkzsMtQruIWm2p'
sp.user_playlist_add_tracks(username, '7qblqNYOVQDOgQIFYBd3sD', song, position=None)
else:
print "Can't get token for", username
I am thrown the following error message;
Traceback (most recent call last):
File "[...]spotifyTest.py", line 19, in <module>
sp.user_playlist_add_tracks(username, '7fBJQPuIZg9U26ew16Ntgb', song)
File "[...]\venv\lib\site-packages\spotipy\client.py", line 457, in user_playlist_add_tracks
payload=ftracks, position=position)
File "[...]\venv\lib\site-packages\spotipy\client.py", line 178, in _post
return self._internal_call('POST', url, payload, kwargs)
File "[...]\venv\lib\site-packages\spotipy\client.py", line 124, in _internal_call
headers=r.headers)
spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/'username'/playlists/7qblqNYOVQDOgQIFYBd3sD/tracks:
Invalid track uri: spotify:track:s
I've had success accessing and creating new playlists, however I've hit a roadblock when it comes to actually adding a track.
I assume it's something simple, the URI is correct (if i search via spotify desktop it works), I'm not sure.
I've tried explicitly passing the URI ID and passing it via variable, no joy with either.
Hi there,
Track must be in an array, song = [6b2oQwSGFkzsMtQruIWm2p]
Thanks @TheFridgeMaster
Most helpful comment
Hi there,
Track must be in an array, song = [6b2oQwSGFkzsMtQruIWm2p]