[GH-ISSUE #1075] Add Tracks to Playlist bug #634

Closed
opened 2026-02-28 00:00:25 +03:00 by kerem · 5 comments
Owner

Originally created by @cmiller11stats on GitHub (Feb 27, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1075

Describe the bug
The function 'playlist_add_items' no longer works for me. Full code output is below. Everything worked perfect yesterday and I made no changes to my code environment. Error message below just showed up today.

Your code
import spotipy
tracklist = [
'6YrEHf7hVlg401qkiKRJG9'
,'1WzAGniIlPgpsVrJb4Bl7L'
,'2XmYgBX5WTd8ZGwzdZNStZ'
]
playlist_id = '6ayPApeknsvxahwtTRwPDG'
spot.playlist_add_items(playlist_id=playlist_id, items=tracklist)

Expected behavior
TrackIds provided are added to playlistId provided.

Output
HTTP Error for POST to https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks with Params: {'position': None} returned 400 due to No uris provided.
Traceback (most recent call last):
File "C:\Users\chris\PycharmProjects\Spotify Code.venv\Lib\site-packages\spotipy\client.py", line 271, in _internal_call
response.raise_for_status()
File "C:\Users\chris\PycharmProjects\Spotify Code.venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
coro = func()
^^^^^^
File "", line 1, in
File "C:\Users\chris\PycharmProjects\Spotify Code.venv\Lib\site-packages\spotipy\client.py", line 1085, in playlist_add_items
return self._post(
^^^^^^^^^^^
File "C:\Users\chris\PycharmProjects\Spotify Code.venv\Lib\site-packages\spotipy\client.py", line 328, in _post
return self._internal_call("POST", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\chris\PycharmProjects\Spotify Code.venv\Lib\site-packages\spotipy\client.py", line 293, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks:
No uris provided., reason: None

Environment:

  • OS: Windows
  • Python version 3.12.0
  • spotipy version2.23.0
  • your IDE (if using any) [e.g. PyCharm, Jupyter Notebook IDE, Google Colab]

Additional context
NA

Originally created by @cmiller11stats on GitHub (Feb 27, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1075 **Describe the bug** The function 'playlist_add_items' no longer works for me. Full code output is below. Everything worked perfect yesterday and I made no changes to my code environment. Error message below just showed up today. **Your code** import spotipy tracklist = [ '6YrEHf7hVlg401qkiKRJG9' ,'1WzAGniIlPgpsVrJb4Bl7L' ,'2XmYgBX5WTd8ZGwzdZNStZ' ] playlist_id = '6ayPApeknsvxahwtTRwPDG' spot.playlist_add_items(playlist_id=playlist_id, items=tracklist) **Expected behavior** TrackIds provided are added to playlistId provided. **Output** HTTP Error for POST to https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks with Params: {'position': None} returned 400 due to No uris provided. Traceback (most recent call last): File "C:\Users\chris\PycharmProjects\Spotify Code\.venv\Lib\site-packages\spotipy\client.py", line 271, in _internal_call response.raise_for_status() File "C:\Users\chris\PycharmProjects\Spotify Code\.venv\Lib\site-packages\requests\models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() ^^^^^^ File "<input>", line 1, in <module> File "C:\Users\chris\PycharmProjects\Spotify Code\.venv\Lib\site-packages\spotipy\client.py", line 1085, in playlist_add_items return self._post( ^^^^^^^^^^^ File "C:\Users\chris\PycharmProjects\Spotify Code\.venv\Lib\site-packages\spotipy\client.py", line 328, in _post return self._internal_call("POST", url, payload, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chris\PycharmProjects\Spotify Code\.venv\Lib\site-packages\spotipy\client.py", line 293, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/6ayPApeknsvxahwtTRwPDG/tracks: No uris provided., reason: None **Environment:** - OS: Windows - Python version 3.12.0 - spotipy version2.23.0 - your IDE (if using any) [e.g. PyCharm, Jupyter Notebook IDE, Google Colab] **Additional context** NA
kerem 2026-02-28 00:00:25 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@rollersteaam commented on GitHub (Feb 27, 2024):

I can also verify this is happening to me. Glad to see someone else has the issue.

The Cause

The issue is because the payload for playlist_add_items (and user_playlist_add_tracks, as it uses that function) is just a list of uris, but Spotify's official documentation (at least, as of the time of writing) expects a dict with a "uris" key.

Here's the erroneous code snippet from Spotipy:

    def playlist_add_items(
        self, playlist_id, items, position=None
    ):
        """ Adds tracks/episodes to a playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - a list of track/episode URIs or URLs
                - position - the position to add the tracks
        """
        plid = self._get_id("playlist", playlist_id)
        ftracks = [self._get_uri("track", tid) for tid in items]
        return self._post(
            "playlists/%s/tracks" % (plid),
            payload=ftracks,
            position=position,
        )

Seems like Spotify may have silently shut down this way of handling it? Very frustrating to diagnose this issue...

Workaround

As a temporary workaround if you're able to, use playlist_replace_items instead. That works for now.

For reference, playlist_replace_items implements this correctly, which is why it works:

    def playlist_replace_items(self, playlist_id, items):
        """ Replace all tracks/episodes in a playlist

            Parameters:
                - playlist_id - the id of the playlist
                - items - list of track/episode ids to comprise playlist
        """
        plid = self._get_id("playlist", playlist_id)
        ftracks = [self._get_uri("track", tid) for tid in items]
        payload = {"uris": ftracks}
        return self._put(
            "playlists/%s/tracks" % (plid), payload=payload
        )
<!-- gh-comment-id:1967452920 --> @rollersteaam commented on GitHub (Feb 27, 2024): I can also verify this is happening to me. Glad to see someone else has the issue. # The Cause The issue is because the payload for `playlist_add_items` (and `user_playlist_add_tracks`, as it uses that function) is just a list of uris, but [Spotify's official documentation](https://developer.spotify.com/documentation/web-api/reference/add-tracks-to-playlist) (at least, as of the time of writing) expects a dict with a "uris" key. Here's the erroneous code snippet from Spotipy: ```python def playlist_add_items( self, playlist_id, items, position=None ): """ Adds tracks/episodes to a playlist Parameters: - playlist_id - the id of the playlist - items - a list of track/episode URIs or URLs - position - the position to add the tracks """ plid = self._get_id("playlist", playlist_id) ftracks = [self._get_uri("track", tid) for tid in items] return self._post( "playlists/%s/tracks" % (plid), payload=ftracks, position=position, ) ``` Seems like Spotify may have silently shut down this way of handling it? Very frustrating to diagnose this issue... # Workaround As a temporary workaround if you're able to, use `playlist_replace_items` instead. That works for now. For reference, `playlist_replace_items` implements this correctly, which is why it works: ```python def playlist_replace_items(self, playlist_id, items): """ Replace all tracks/episodes in a playlist Parameters: - playlist_id - the id of the playlist - items - list of track/episode ids to comprise playlist """ plid = self._get_id("playlist", playlist_id) ftracks = [self._get_uri("track", tid) for tid in items] payload = {"uris": ftracks} return self._put( "playlists/%s/tracks" % (plid), payload=payload ) ```
Author
Owner

@lfg6000 commented on GitHub (Feb 27, 2024):

yep the spotify server appears to no longer accept
items = ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']

you must now pass in
items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']}
or items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'], 'position': X }

a revised spoitipy - client.py - playlist_add_items() is needed
where you just pass on the items param directly to spotify

def playlist_add_items(self, playlist_id, items, position=None):
    plid = self._get_id("playlist", playlist_id)
    return self._post("playlists/%s/tracks" % (plid), payload=items) 

where items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']}
the tracks are added as expected

wonder if spotify knows they broke spotipy?

here is the web app i built using spotipy: spotifyfinder.com (many thanks to all the folks who work spotipy)
the web app allows you to search for dups across playlists and search across playlists for a track or artist, etc...
the web app is free, open source, tracker free, ad free.

<!-- gh-comment-id:1967664725 --> @lfg6000 commented on GitHub (Feb 27, 2024): yep the spotify server appears to no longer accept items = ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'] you must now pass in items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']} or items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'], 'position': X } a revised spoitipy - client.py - playlist_add_items() is needed where you just pass on the items param directly to spotify ``` def playlist_add_items(self, playlist_id, items, position=None): plid = self._get_id("playlist", playlist_id) return self._post("playlists/%s/tracks" % (plid), payload=items) ``` where items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']} the tracks are added as expected wonder if spotify knows they broke spotipy? here is the web app i built using spotipy: [spotifyfinder.com](url) (many thanks to all the folks who work spotipy) the web app allows you to search for dups across playlists and search across playlists for a track or artist, etc... the web app is free, open source, tracker free, ad free.
Author
Owner

@mitsuru-nashimoto commented on GitHub (Feb 28, 2024):

Does the success of playlist_replace_items over playlist_add_items indicate a bug in spotipy? Is there any plan to address this issue in future updates?

<!-- gh-comment-id:1968113155 --> @mitsuru-nashimoto commented on GitHub (Feb 28, 2024): Does the success of playlist_replace_items over playlist_add_items indicate a bug in spotipy? Is there any plan to address this issue in future updates?
Author
Owner

@lfg6000 commented on GitHub (Feb 29, 2024):

it appears spotify reverted the change and spotipy playlist_add_items() is working again.
spotify is once again accepting
method = POST
url = 'https://api.spotify.com/v1/playlists/1n2STXHae0Wg6ZV0OYwToy/tracks'
payload = ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']

i suspect spotify will break it again because the spotify docs say the payload needs to be
payload = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'], 'position': X }

<!-- gh-comment-id:1970425638 --> @lfg6000 commented on GitHub (Feb 29, 2024): it appears spotify reverted the change and spotipy playlist_add_items() is working again. spotify is once again accepting method = POST url = 'https://api.spotify.com/v1/playlists/1n2STXHae0Wg6ZV0OYwToy/tracks' payload = ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'] i suspect spotify will break it again because the spotify docs say the payload needs to be payload = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6'], 'position': X }
Author
Owner

@stephanebruckert commented on GitHub (Jul 9, 2024):

Looks like this was a temporary issue on the API side, closing

<!-- gh-comment-id:2218356753 --> @stephanebruckert commented on GitHub (Jul 9, 2024): Looks like this was a temporary issue on the API side, closing
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#634
No description provided.