mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 00:25:54 +03:00
[GH-ISSUE #1075] Add Tracks to Playlist bug #634
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#634
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 @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:
Additional context
NA
@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(anduser_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:
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_itemsinstead. That works for now.For reference,
playlist_replace_itemsimplements this correctly, which is why it works:@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
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.
@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?
@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 }
@stephanebruckert commented on GitHub (Jul 9, 2024):
Looks like this was a temporary issue on the API side, closing