mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #931] playlist_add_items not working #557
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#557
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
@dieser-niko commented on GitHub (Jan 17, 2023):
It looks like your variable
song_uriis simply"spotify:track:s", could you check?@DeepVasoya08 commented on GitHub (Jan 17, 2023):
Yes i checked twice, both song uri and playlist uri
@stephanebruckert commented on GitHub (Jan 17, 2023):
Please provide a minimal reproducible example and print
song_urifor us.@DeepVasoya08 commented on GitHub (Jan 18, 2023):
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
@stephanebruckert commented on GitHub (Jan 18, 2023):
OK according to https://spotipy.readthedocs.io/en/2.22.0/#spotipy.client.Spotify.playlist_add_items,
itemsneeds to be a list.So use
playlist_add_items(playlist_id, [song_uri])instead ofplaylist_add_items(playlist_id, song_uri)@DeepVasoya08 commented on GitHub (Jan 18, 2023):
nice catch👍
Thank you!