Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not remove tracks, please check parameters with playlist_remove_specific_occurrences_of_items #1063

Open
saarimrahman opened this issue Dec 16, 2023 · 3 comments
Labels

Comments

@saarimrahman
Copy link

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.
@Jack-Dane
Copy link
Contributor

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
spotify/web-api#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.

@saarimrahman
Copy link
Author

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

@Jack-Dane
Copy link
Contributor

Jack-Dane commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants