[GH-ISSUE #1106] How to delete playlists using spotipy #659

Closed
opened 2026-02-28 00:00:37 +03:00 by kerem · 7 comments
Owner

Originally created by @JackDyre on GitHub (May 14, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1106

Which method should I use to delete a playlist that I own? I didn't see any methods in the documentation that directly delete a playlist (though I could have just missed it) and ChatGPT told me to use current_user_unfollow_playlist, but I get an error whenever I use it:

>>> from main import api_request_manager as a
>>> a.sp.current_user_unfollow_playlist("https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f")
HTTP Error for DELETE to https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers with Params: {} returned 404 due to None
Traceback (most recent call last):
  File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 271, in _internal_call
    response.raise_for_status()
  File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 1069, in current_user_unfollow_playlist
    return self._delete(
           ^^^^^^^^^^^^^
  File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 333, in _delete
    return self._internal_call("DELETE", url, payload, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 293, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers:
 None, reason: None

Am I using the wrong method or am I using the method incorrectly?

Originally created by @JackDyre on GitHub (May 14, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1106 Which method should I use to delete a playlist that I own? I didn't see any methods in the documentation that directly delete a playlist (though I could have just missed it) and ChatGPT told me to use current_user_unfollow_playlist, but I get an error whenever I use it: ```python >>> from main import api_request_manager as a >>> a.sp.current_user_unfollow_playlist("https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f") HTTP Error for DELETE to https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers with Params: {} returned 404 due to None Traceback (most recent call last): File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 271, in _internal_call response.raise_for_status() File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 1069, in current_user_unfollow_playlist return self._delete( ^^^^^^^^^^^^^ File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 333, in _delete return self._internal_call("DELETE", url, payload, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\riley\Documents\GitHub\spotify-file-storage\cpy_venv\Lib\site-packages\spotipy\client.py", line 293, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/playlists/https://open.spotify.com/playlist/1Rqvqd7cI4AoeDn5Ei3mql?si=0e4a6ef55eeb486f/followers: None, reason: None ``` Am I using the wrong method or am I using the method incorrectly?
kerem 2026-02-28 00:00:37 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@JackDyre commented on GitHub (May 15, 2024):

I figured out that you must input a playlist ID rather than a URL

From the docs:

Spotipy supports a number of different ID types:

Spotify URI - The resource identifier that you can enter, for example, in the Spotify Desktop client’s search box to locate an artist, album, or track. Example: spotify:track:6rqhFgbbKwnb9MLmUQDhG6
Spotify URL - An HTML link that opens a track, album, app, playlist or other Spotify resource in a Spotify client. Example: http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6
Spotify ID - A base-62 number that you can find at the end of the Spotify URI (see above) for an artist, track, album, etc. Example: 6rqhFgbbKwnb9MLmUQDhG6

In general, any Spotipy method that needs an artist, album, track or playlist ID will accept ids in any of the above form

Should this method only accept an IDs and not URLS?

<!-- gh-comment-id:2111373939 --> @JackDyre commented on GitHub (May 15, 2024): I figured out that you must input a playlist ID rather than a URL From the [docs](https://spotipy.readthedocs.io/en/2.22.1/#ids-uris-and-urls): >Spotipy supports a number of different ID types: > >Spotify URI - The resource identifier that you can enter, for example, in the Spotify Desktop client’s search box to locate an artist, album, or track. Example: spotify:track:6rqhFgbbKwnb9MLmUQDhG6 >Spotify URL - An HTML link that opens a track, album, app, playlist or other Spotify resource in a Spotify client. Example: http://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6 >Spotify ID - A base-62 number that you can find at the end of the Spotify URI (see above) for an artist, track, album, etc. Example: 6rqhFgbbKwnb9MLmUQDhG6 >**__In general, any Spotipy method that needs an artist, album, track or playlist ID will accept ids in any of the above form__** Should this method only accept an IDs and not URLS?
Author
Owner

@dieser-niko commented on GitHub (May 15, 2024):

Yep, I know about this already. This part of the docs is somewhat misleading because normally spotipy converts URLs automatically (with Spotify._get_id), but this conversion doesn't happen everywhere. @stephanebruckert is there a reason for that?

<!-- gh-comment-id:2112037808 --> @dieser-niko commented on GitHub (May 15, 2024): Yep, I know about this already. This part of the docs is somewhat misleading because normally spotipy converts URLs automatically (with `Spotify._get_id`), but this conversion doesn't happen everywhere. @stephanebruckert is there a reason for that?
Author
Owner

@dieser-niko commented on GitHub (May 17, 2024):

Oh, sorry, I just realised I didn't read your question properly. Deleting playlists is not directly possible.

This may sound silly (because it is imo), but Spotify believes that if you decide to delete your playlist, but there are some followers who like it, then the playlist won't actually be deleted, it will just be removed from your library.

You can try this yourself by creating a playlist, copying the link, deleting the playlist and then trying to access the playlist via the link. You will then have your playlist back.

I don't really know if the playlists will deleted at some point. If you go to the recover playlists, Spotify states that they will remove the playlist from the list after 90 days, but I can't confirm nor deny if this would delete the playlist for good.

So to answer your question: ChatGPT gave you the right answer. But for some reason, there's no URI validation, so just make sure that you're using 1Rqvqd7cI4AoeDn5Ei3mql instead of the whole link as an argument.

<!-- gh-comment-id:2117535301 --> @dieser-niko commented on GitHub (May 17, 2024): Oh, sorry, I just realised I didn't read your question properly. Deleting playlists is not directly possible. This may sound silly (because it is imo), but [Spotify believes](https://developer.spotify.com/documentation/web-api/concepts/playlists#following-and-unfollowing-a-playlist) that if you decide to delete your playlist, but there are some followers who like it, then the playlist won't actually be deleted, it will just be removed from your library. You can try this yourself by creating a playlist, copying the link, deleting the playlist and then trying to access the playlist via the link. You will then have your playlist back. I don't really know if the playlists will deleted at some point. If you go to the [recover playlists](https://www.spotify.com/de/account/recover-playlists/), Spotify states that they will remove the playlist from the list after 90 days, but I can't confirm nor deny if this would delete the playlist for good. So to answer your question: ChatGPT gave you the right answer. But for some reason, there's no URI validation, so just make sure that you're using `1Rqvqd7cI4AoeDn5Ei3mql` instead of the whole link as an argument.
Author
Owner

@JackDyre commented on GitHub (Jun 27, 2024):

Would the fix just be as simple as adding self._get_id("playlist", playlist_id) inside the f string in the current_user_unfollow_playlist() method?

For example:

    def current_user_unfollow_playlist(self, playlist_id):
        """ Unfollows (deletes) a playlist for the current authenticated
            user

            Parameters:
                - name - the name of the playlist
        """
        return self._delete(
            f"playlists/{self._get_id("playlist", playlist_id)}/followers"

Additionally, shouldn't the name param in the docstring be changed to playlist_id?

<!-- gh-comment-id:2195768533 --> @JackDyre commented on GitHub (Jun 27, 2024): Would the fix just be as simple as adding `self._get_id("playlist", playlist_id)` inside the f string in the `current_user_unfollow_playlist()` method? For example: ```python def current_user_unfollow_playlist(self, playlist_id): """ Unfollows (deletes) a playlist for the current authenticated user Parameters: - name - the name of the playlist """ return self._delete( f"playlists/{self._get_id("playlist", playlist_id)}/followers" ``` Additionally, shouldn't the `name` param in the docstring be changed to `playlist_id`?
Author
Owner

@stephanebruckert commented on GitHub (Jun 27, 2024):

That should do it @JackDyre, would you be up to open a PR for it?

<!-- gh-comment-id:2195773851 --> @stephanebruckert commented on GitHub (Jun 27, 2024): That should do it @JackDyre, would you be up to open a PR for it?
Author
Owner

@JackDyre commented on GitHub (Jun 27, 2024):

Sure!

<!-- gh-comment-id:2195789112 --> @JackDyre commented on GitHub (Jun 27, 2024): Sure!
Author
Owner

@JackDyre commented on GitHub (Jun 28, 2024):

Is there a reason why _get_id() and similar methods are private? I don't understand why they are even methods of Spotify in the first place. Being able to convert between IDs and URIs seems like it would be useful to have in a project.

<!-- gh-comment-id:2195964000 --> @JackDyre commented on GitHub (Jun 28, 2024): Is there a reason why `_get_id()` and similar methods are private? I don't understand why they are even methods of `Spotify` in the first place. Being able to convert between IDs and URIs seems like it would be useful to have in a project.
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#659
No description provided.