[GH-ISSUE #931] playlist_add_items not working #557

Closed
opened 2026-02-27 23:23:20 +03:00 by kerem · 6 comments
Owner

Originally created by @DeepVasoya08 on GitHub (Jan 17, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/931

Describe the bug
playlist_add_items () is broken it is throwing error

Your code
try: self.spotify.playlist_add_items(playlist_id, song_uri) return True except spotipy.SpotifyException as e: raise Exception(e)

while this line is perfectly working -> url = (f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks?uris={song_uri}")

Expected behavior
song should be added to playlist

Output
Exception: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/1LMi4K1NtYWRUkU2kKjJQo/tracks:
Invalid track uri: spotify:track:s, reason: None

Environment:

  • OS: [Windows]
  • Python version [3.10.9]
  • spotipy version [2.22.0]
Originally created by @DeepVasoya08 on GitHub (Jan 17, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/931 **Describe the bug** playlist_add_items () is broken it is throwing error **Your code** `try: self.spotify.playlist_add_items(playlist_id, song_uri) return True except spotipy.SpotifyException as e: raise Exception(e)` **while this line is perfectly working -> url = (f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks?uris={song_uri}")** **Expected behavior** song should be added to playlist **Output** Exception: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/1LMi4K1NtYWRUkU2kKjJQo/tracks: Invalid track uri: spotify:track:s, reason: None **Environment:** - OS: [Windows] - Python version [3.10.9] - spotipy version [2.22.0]
kerem 2026-02-27 23:23:20 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@dieser-niko commented on GitHub (Jan 17, 2023):

It looks like your variable song_uri is simply "spotify:track:s", could you check?

<!-- gh-comment-id:1385673655 --> @dieser-niko commented on GitHub (Jan 17, 2023): It looks like your variable `song_uri` is simply `"spotify:track:s"`, could you check?
Author
Owner

@DeepVasoya08 commented on GitHub (Jan 17, 2023):

It looks like your variable song_uri is simply "spotify:track:s", could you check?

Yes i checked twice, both song uri and playlist uri

<!-- gh-comment-id:1385689058 --> @DeepVasoya08 commented on GitHub (Jan 17, 2023): > It looks like your variable `song_uri` is simply `"spotify:track:s"`, could you check? Yes i checked twice, both song uri and playlist uri
Author
Owner

@stephanebruckert commented on GitHub (Jan 17, 2023):

Please provide a minimal reproducible example and print song_uri for us.

<!-- gh-comment-id:1385701372 --> @stephanebruckert commented on GitHub (Jan 17, 2023): Please provide a minimal reproducible example and print `song_uri` for us.
Author
Owner

@DeepVasoya08 commented on GitHub (Jan 18, 2023):

Please provide a minimal reproducible example and print song_uri for us.

here is full output of the code:

song_uri--------> spotify:track:2VGs7EmaIxq96Wcog6DQOc
playlist_id------> 77VRlvcF6Qm5BFHfCjauaj

HTTP Error for POST to https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks with Params: {'position': None} returned 400 due to Invalid track uri: spotify:track:s

Traceback (most recent call last):
File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 245, in _internal_call
response.raise_for_status()
File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\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/77VRlvcF6Qm5BFHfCjauaj/tracks

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\projects\only_music\spotify_client.py", line 80, in add_song
self.spotify.playlist_add_items(playlist_id, song_uri)
File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 1040, in playlist_add_items
return self._post(
File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 302, in _post
return self._internal_call("POST", url, payload, kwargs)
File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 267, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks:
Invalid track uri: spotify:track:s, reason: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\projects\only_music\main.py", line 106, in
main()
File "d:\projects\only_music\main.py", line 100, in main
add_song = spotify_client.add_song(song_uri, playlist["id"])
File "d:\projects\only_music\spotify_client.py", line 83, in add_song
raise Exception(e)
Exception: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks:
Invalid track uri: spotify:track:s, reason: None

<!-- gh-comment-id:1386475413 --> @DeepVasoya08 commented on GitHub (Jan 18, 2023): > Please provide a minimal reproducible example and print `song_uri` for us. here is full output of the code: song_uri--------> spotify:track:2VGs7EmaIxq96Wcog6DQOc playlist_id------> 77VRlvcF6Qm5BFHfCjauaj HTTP Error for POST to https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks with Params: {'position': None} returned 400 due to Invalid track uri: spotify:track:s Traceback (most recent call last): File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 245, in _internal_call response.raise_for_status() File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\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/77VRlvcF6Qm5BFHfCjauaj/tracks During handling of the above exception, another exception occurred: Traceback (most recent call last): File "d:\projects\only_music\spotify_client.py", line 80, in add_song self.spotify.playlist_add_items(playlist_id, song_uri) File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 1040, in playlist_add_items return self._post( File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 302, in _post return self._internal_call("POST", url, payload, kwargs) File "C:\Users\deepv.virtualenvs\only_music-SaPE63u8\lib\site-packages\spotipy\client.py", line 267, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks: Invalid track uri: spotify:track:s, reason: None During handling of the above exception, another exception occurred: Traceback (most recent call last): File "d:\projects\only_music\main.py", line 106, in main() File "d:\projects\only_music\main.py", line 100, in main add_song = spotify_client.add_song(song_uri, playlist["id"]) File "d:\projects\only_music\spotify_client.py", line 83, in add_song raise Exception(e) Exception: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/77VRlvcF6Qm5BFHfCjauaj/tracks: Invalid track uri: spotify:track:s, reason: None
Author
Owner

@stephanebruckert commented on GitHub (Jan 18, 2023):

OK according to https://spotipy.readthedocs.io/en/2.22.0/#spotipy.client.Spotify.playlist_add_items, items needs to be a list.

So use playlist_add_items(playlist_id, [song_uri]) instead of playlist_add_items(playlist_id, song_uri)

<!-- gh-comment-id:1386819050 --> @stephanebruckert commented on GitHub (Jan 18, 2023): OK according to https://spotipy.readthedocs.io/en/2.22.0/#spotipy.client.Spotify.playlist_add_items, `items` needs to be a list. So use `playlist_add_items(playlist_id, [song_uri])` instead of `playlist_add_items(playlist_id, song_uri)`
Author
Owner

@DeepVasoya08 commented on GitHub (Jan 18, 2023):

OK according to https://spotipy.readthedocs.io/en/2.22.0/#spotipy.client.Spotify.playlist_add_items, items needs to be a list.

So use playlist_add_items(playlist_id, [song_uri]) instead of playlist_add_items(playlist_id, song_uri)

nice catch👍

Thank you!

<!-- gh-comment-id:1387235498 --> @DeepVasoya08 commented on GitHub (Jan 18, 2023): > OK according to https://spotipy.readthedocs.io/en/2.22.0/#spotipy.client.Spotify.playlist_add_items, `items` needs to be a list. > > So use `playlist_add_items(playlist_id, [song_uri])` instead of `playlist_add_items(playlist_id, song_uri)` nice catch👍 Thank you!
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#557
No description provided.