Spotipy: user_playlist_remove_all_occurrences_of_tracks() throws invalid track uri error

Created on 6 Mar 2017  路  3Comments  路  Source: plamere/spotipy

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('', '', ''),
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

Most helpful comment

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')



md5-ed75a79dfc9a1a58dae579919d35fd73



print(complete[0][3])

spotify:track:1QEEqeFIZktqIpPI4jSVSF



md5-133095cb72193f9b7c96257ea6e863c5



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



md5-f8a5a3be02552c7fff050e1f426cb872



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.

All 3 comments

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')



md5-ed75a79dfc9a1a58dae579919d35fd73



print(complete[0][3])

spotify:track:1QEEqeFIZktqIpPI4jSVSF



md5-133095cb72193f9b7c96257ea6e863c5



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



md5-f8a5a3be02552c7fff050e1f426cb872



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.

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]])

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kurchunk picture Kurchunk  路  3Comments

DylanMeeus picture DylanMeeus  路  4Comments

jkvlevin picture jkvlevin  路  6Comments

astralmedia picture astralmedia  路  4Comments

JessicaMartini212887 picture JessicaMartini212887  路  5Comments