-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Tracks to Playlist bug #1075
Comments
I can also verify this is happening to me. Glad to see someone else has the issue. The CauseThe issue is because the payload for 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... WorkaroundAs a temporary workaround if you're able to, use For reference, 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
) |
yep the spotify server appears to no longer accept you must now pass in a revised spoitipy - client.py - playlist_add_items() is needed
where items = {'uris': ['spotify:track:6HG5MFydepB9F8DAP0ejDD', 'spotify:track:3yQ4dy23XekcMsdeaBXZR6']} 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) |
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? |
it appears spotify reverted the change and spotipy playlist_add_items() is working again. i suspect spotify will break it again because the spotify docs say the payload needs to be |
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
The text was updated successfully, but these errors were encountered: