[GH-ISSUE #168] user_playlist_remove_all_occurrences_of_tracks() throws invalid track uri error #83

Closed
opened 2026-02-27 23:20:45 +03:00 by kerem · 3 comments
Owner

Originally created by @gauthamanms on GitHub (Mar 6, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/168

I got myself authenticated and could access and work well with other functions which requires aunthetication in spotipy. However I couldnt get user_playlist_remove_all_occurrences_of_tracks() work.
I tried Keeping the code as simple as possible by trying to pass user_playlist_remove_all_occurrences_of_tracks('<user_id>', '<playlist_id>', '<track_id>'),
but it shows the following error:

SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/msgauthaman/playlists/4Sc7nWBUrNnhjSoMDyPCdE/tracks:
JSON body contains an invalid track uri: spotify:track:5

Originally created by @gauthamanms on GitHub (Mar 6, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/168 I got myself authenticated and could access and work well with other functions which requires aunthetication in spotipy. However I couldnt get user_playlist_remove_all_occurrences_of_tracks() work. I tried Keeping the code as simple as possible by trying to pass user_playlist_remove_all_occurrences_of_tracks('<user_id>', '<playlist_id>', '<track_id>'), but it shows the following error: SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/users/msgauthaman/playlists/4Sc7nWBUrNnhjSoMDyPCdE/tracks: JSON body contains an invalid track uri: spotify:track:5
kerem closed this issue 2026-02-27 23:20:45 +03:00
Author
Owner

@noahbetz commented on GitHub (Jun 1, 2017):

I made a GitHub account just to respond to this. I know this is an old question, but I'm responding to it because I came across this question when I had the problem. Currently, my code pulls the song name, album, artist, and URI from each song in a playlist and stores it in a list called complete. Here's an example of the first two entries in the list:

print(complete[0])

('More Than a Feeling', 'Boston', 'Boston', 'spotify:track:1QEEqeFIZktqIpPI4jSVSF')
print(complete[1])

('Peace of Mind', 'Boston', 'Boston', 'spotify:track:1GqlvSEtMx5xbGptxOTTyk')

With this you can further access a specific part of each entry:

print(complete[0][3])

spotify:track:1QEEqeFIZktqIpPI4jSVSF

Here's what I was trying to do before, which is basically your code:

sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', complete[0][3])

This throws the same error:
JSON body contains an invalid track uri: spotify:track:1

What fixed it for me was declaring a new variable tracks, which contains a list of only complete[0][3].

tracks = [complete[0][3]]
sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', tracks)

I don't know why this works, but it's how I fixed the problem.

<!-- gh-comment-id:305547635 --> @noahbetz commented on GitHub (Jun 1, 2017): I made a GitHub account just to respond to this. I know this is an old question, but I'm responding to it because I came across this question when I had the problem. Currently, my code pulls the song name, album, artist, and URI from each song in a playlist and stores it in a list called complete. Here's an example of the first two entries in the list: ``` print(complete[0]) ('More Than a Feeling', 'Boston', 'Boston', 'spotify:track:1QEEqeFIZktqIpPI4jSVSF') ``` ``` print(complete[1]) ('Peace of Mind', 'Boston', 'Boston', 'spotify:track:1GqlvSEtMx5xbGptxOTTyk') ``` With this you can further access a specific part of each entry: ``` print(complete[0][3]) spotify:track:1QEEqeFIZktqIpPI4jSVSF ``` Here's what I was trying to do before, which is basically your code: ``` sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', complete[0][3]) ``` This throws the same error: `JSON body contains an invalid track uri: spotify:track:1` What fixed it for me was declaring a new variable tracks, which contains a list of only complete[0][3]. ``` tracks = [complete[0][3]] sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', tracks) ``` I don't know why this works, but it's how I fixed the problem.
Author
Owner

@cameron-gagnon commented on GitHub (May 18, 2019):

It doesn't need to be a new variable, it just needs to be within an array, such as the 's' in tracks slightly suggests.
This should work as well:
sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', [complete[0][3]])

<!-- gh-comment-id:493710386 --> @cameron-gagnon commented on GitHub (May 18, 2019): It doesn't need to be a new variable, it just needs to be within an array, such as the 's' in tracks slightly suggests. This should work as well: `sp.user_playlist_remove_all_occurrences_of_tracks(username, '4nJyAWMGALHKx6I67Ct9x8', [complete[0][3]])`
Author
Owner

@stephanebruckert commented on GitHub (Jan 13, 2020):

Indeed, as per the doc it should be an array of track_ids

<!-- gh-comment-id:573915885 --> @stephanebruckert commented on GitHub (Jan 13, 2020): Indeed, as per the doc it should be an array of `track_ids`
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#83
No description provided.