[GH-ISSUE #274] spotipy: Invalid track uri: spotify:track:s #148

Closed
opened 2026-02-27 23:21:05 +03:00 by kerem · 2 comments
Owner

Originally created by @callrua on GitHub (Apr 12, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/274

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.

Originally created by @callrua on GitHub (Apr 12, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/274 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; ```python 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.
kerem closed this issue 2026-02-27 23:21:05 +03:00
Author
Owner

@kylegbakker commented on GitHub (Apr 12, 2018):

Hi there,

Track must be in an array, song = [6b2oQwSGFkzsMtQruIWm2p]

<!-- gh-comment-id:380765225 --> @kylegbakker commented on GitHub (Apr 12, 2018): Hi there, Track must be in an array, song = [6b2oQwSGFkzsMtQruIWm2p]
Author
Owner

@callrua commented on GitHub (Apr 12, 2018):

Thanks @TheFridgeMaster

<!-- gh-comment-id:380765807 --> @callrua commented on GitHub (Apr 12, 2018): Thanks @TheFridgeMaster
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#148
No description provided.