[GH-ISSUE #1063] Could not remove tracks, please check parameters with playlist_remove_specific_occurrences_of_items #626

Closed
opened 2026-02-28 00:00:22 +03:00 by kerem · 4 comments
Owner

Originally created by @saarimrahman on GitHub (Dec 16, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1063

Hi, even though items is formatted correctly, I'm receiving an error of " Could not remove tracks, please check parameters., reason: None" with playlist_remove_specific_occurrences_of_items

sp = get_authorized_spotify_client()
items = [{'uri': track['track']['id'], 'positions': [track['position']]} for track in tracks]
logging.info(f'{items=}')
sp.playlist_remove_specific_occurrences_of_items(playlist_id, items)
2023-12-16 14:34:52 [    INFO] items=[{'uri': '5Z3trOR982mBrJcPfrLUsq', 'positions': [5]}, {'uri': '2OZZpID4LgZ0GGm8XB99e3', 'positions': [7]}, {'uri': '764aj78vmTA8kMUMY0LVdR', 'positions': [9]}, {'uri': '68lTEhMEx4MxDCJypT6bXE', 'positions': [11]}, {'uri': '3PBC860LAeS4utDAqlqIe2', 'positions': [3]}, {'uri': '1rGd2CoMxEg2dnaytLY5ZG', 'positions': [12]}, {'uri': '0psbBdxOb3A8WMuG3ludUw', 'positions': [1]}, {'uri': '1t0Jmqg1pKVBbxjQFZebeR', 'positions': [15]}] (spotify.py:279)
  File "/Users/saarim/projects/project-boilerplate/python/app/routes/spotify.py", line 280, in remove_duplicates
    sp.playlist_remove_specific_occurrences_of_items(playlist_id, items)
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 1182, in playlist_remove_specific_occurrences_of_items
    return self._delete(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 331, in _delete
    return self._internal_call("DELETE", url, payload, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 291, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/478D5udPmRAfuMvzUaDxNn/tracks:
 Could not remove tracks, please check parameters., reason: None
  • playlist_id = 478D5udPmRAfuMvzUaDxNn. What am I doing wrong? Items looks formatted as it is in the docs.
Originally created by @saarimrahman on GitHub (Dec 16, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1063 <!--- Please make sure you've: - read the FAQ https://github.com/plamere/spotipy/blob/master/FAQ.md - read the documentation https://spotipy.readthedocs.io/en/latest/ - searched older issues If your question is about code, please share the code you are using ---> Hi, even though items is formatted correctly, I'm receiving an error of " Could not remove tracks, please check parameters., reason: None" with `playlist_remove_specific_occurrences_of_items` ``` sp = get_authorized_spotify_client() items = [{'uri': track['track']['id'], 'positions': [track['position']]} for track in tracks] logging.info(f'{items=}') sp.playlist_remove_specific_occurrences_of_items(playlist_id, items) ``` ``` 2023-12-16 14:34:52 [ INFO] items=[{'uri': '5Z3trOR982mBrJcPfrLUsq', 'positions': [5]}, {'uri': '2OZZpID4LgZ0GGm8XB99e3', 'positions': [7]}, {'uri': '764aj78vmTA8kMUMY0LVdR', 'positions': [9]}, {'uri': '68lTEhMEx4MxDCJypT6bXE', 'positions': [11]}, {'uri': '3PBC860LAeS4utDAqlqIe2', 'positions': [3]}, {'uri': '1rGd2CoMxEg2dnaytLY5ZG', 'positions': [12]}, {'uri': '0psbBdxOb3A8WMuG3ludUw', 'positions': [1]}, {'uri': '1t0Jmqg1pKVBbxjQFZebeR', 'positions': [15]}] (spotify.py:279) ``` ``` File "/Users/saarim/projects/project-boilerplate/python/app/routes/spotify.py", line 280, in remove_duplicates sp.playlist_remove_specific_occurrences_of_items(playlist_id, items) File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 1182, in playlist_remove_specific_occurrences_of_items return self._delete( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 331, in _delete return self._internal_call("DELETE", url, payload, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/spotipy/client.py", line 291, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/478D5udPmRAfuMvzUaDxNn/tracks: Could not remove tracks, please check parameters., reason: None ``` - playlist_id = `478D5udPmRAfuMvzUaDxNn`. What am I doing wrong? Items looks formatted as it is in the docs.
kerem 2026-02-28 00:00:22 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Jack-Dane commented on GitHub (Jan 2, 2024):

It doesn't look like the positions parameter is supported anymore. The documentation doesn't mention it: https://developer.spotify.com/documentation/web-api/reference/remove-tracks-playlist (only has the uri).

There are also a few other tickets that mention the same response error string:
https://community.spotify.com/t5/Spotify-for-Developers/How-delete-one-or-more-elements-from-playlist/td-p/5185630
https://github.com/spotify/web-api/issues/989

As far as I can tell, it is only needed if there is the same song in the playlist twice and you want to remove a specific occurrence.

<!-- gh-comment-id:1874629129 --> @Jack-Dane commented on GitHub (Jan 2, 2024): It doesn't look like the `positions` parameter is supported anymore. The documentation doesn't mention it: https://developer.spotify.com/documentation/web-api/reference/remove-tracks-playlist (only has the `uri`). There are also a few other tickets that mention the same response error string: https://community.spotify.com/t5/Spotify-for-Developers/How-delete-one-or-more-elements-from-playlist/td-p/5185630 https://github.com/spotify/web-api/issues/989 As far as I can tell, it is only needed if there is the same song in the playlist twice and you want to remove a specific occurrence.
Author
Owner

@saarimrahman commented on GitHub (Jan 4, 2024):

Appreciate the response! Left a comment on that thread, hopefully someone responds.

Sadly my use case is exactly trying to remove the same song in a playlist twice: https://app.saarim.me/find-duplicates

<!-- gh-comment-id:1876203853 --> @saarimrahman commented on GitHub (Jan 4, 2024): Appreciate the response! Left a comment on that thread, hopefully someone responds. Sadly my use case is exactly trying to remove the same song in a playlist twice: https://app.saarim.me/find-duplicates
Author
Owner

@Jack-Dane commented on GitHub (Jan 4, 2024):

@saarimrahman, I see, in the meantime you should be able to work around this issue (if you haven't already used this as a solution).

You can remove just the URIs that have duplicates and then add them back to their first position with:

sp.playlist_add_items("<playlist_id>", ["<track_id>"], position=x)

This will need to be done for each duplicate individually to ensure the order of songs isn't affected.

But if you don't care about the order, you can remove all the duplicates in one request (as you have been doing) and then add one of each back with one request. You can pass an array of tracks. See this example examples/add_tracks_to_playlist.py.

<!-- gh-comment-id:1877535309 --> @Jack-Dane commented on GitHub (Jan 4, 2024): @saarimrahman, I see, in the meantime you should be able to work around this issue (if you haven't already used this as a solution). You can remove just the URIs that have duplicates and then add them back to their first position with: ``` sp.playlist_add_items("<playlist_id>", ["<track_id>"], position=x) ``` This will need to be done for each duplicate individually to ensure the order of songs isn't affected. But if you don't care about the order, you can remove all the duplicates in one request (as you have been doing) and then add one of each back with one request. You can pass an array of tracks. See this example examples/add_tracks_to_playlist.py.
Author
Owner

@stephanebruckert commented on GitHub (May 22, 2025):

Closing as Spotify removed this endpoint, making it a deprecated method in spotipy. I updated the spotipy doc to reflect that in https://github.com/spotipy-dev/spotipy/pull/1202

Alternatively you can use playlist_remove_all_occurrences_of_items(playlist_id, items, snapshot_id=None) but be aware that it can come with issues due to changes on the Spotify side again: https://github.com/spotipy-dev/spotipy/issues/1098 shows all tracks with the same ID will be removed from the playlist, making it difficult to remove duplicates.

<!-- gh-comment-id:2902241190 --> @stephanebruckert commented on GitHub (May 22, 2025): Closing as Spotify removed this endpoint, making it a deprecated method in spotipy. I updated the spotipy doc to reflect that in https://github.com/spotipy-dev/spotipy/pull/1202 Alternatively you can use [`playlist_remove_all_occurrences_of_items(playlist_id, items, snapshot_id=None)`](https://spotipy.readthedocs.io/en/2.25.1/#spotipy.client.Spotify.playlist_remove_all_occurrences_of_items) but be aware that it can come with issues due to changes on the Spotify side again: https://github.com/spotipy-dev/spotipy/issues/1098 shows all tracks with the same ID will be removed from the playlist, making it [difficult to remove duplicates](https://community.spotify.com/t5/Spotify-for-Developers/Positions-field-in-JSON-body-is-ignored-when-removing-tracks/m-p/6055483/highlight/true#M13828).
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#626
No description provided.