Help Wizard

Step 1



Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...


Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...


spotipy API base-62 error for adding track to playlist

spotipy API base-62 error for adding track to playlist

Hi, I'm running into an error using the `spotipy` package. It seems to say that the playlist ID or track ID isn't valid, but I can visit the link to both and they work. Unsure what I'm doing wrong.




import requests
import os
import spotipy
from spotipy.oauth2 import SpotifyOAuth

os.environ['SPOTIPY_REDIRECT_URI'] = 'http://localhost'

scope = "playlist-modify-public playlist-modify-private user-library-modify"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
sp.playlist_add_items('7AatTbqsTPhQ4bTRDqXaQH', '6nz35DNIzbtj5ztpDEcW1j')




This gives the following error:




>>> sp.playlist_add_items('7AatTbqsTPhQ4bTRDqXaQH', '6nz35DNIzbtj5ztpDEcW1j')
HTTP Error for POST to with Params: {'position': None} returned 400 due to Invalid base62 id
Traceback (most recent call last):
  File ".../.venv/lib/python3.11/site-packages/spotipy/", line 271, in _internal_call
  File ".../.venv/lib/python3.11/site-packages/requests/", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../.venv/lib/python3.11/site-packages/spotipy/", line 1085, in playlist_add_items
    return self._post(
  File ".../.venv/lib/python3.11/site-packages/spotipy/", line 328, in _post
    return self._internal_call("POST", url, payload, kwargs)
  File ".../.venv/lib/python3.11/site-packages/spotipy/", line 293, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 -
 Invalid base62 id, reason: None




1 Reply

In the documentation you can read:

items - a list of track/episode URIs or URLs


You can try to add [ and ] around the track id. If that doesn't fix it fully, you should also add spotify:track: to each id.

XimzendRising Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts