Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

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

Loading issue...

Loading ongoing issues...

VIEW ALL

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_CLIENT_ID'] = '$MY_CLIENT_ID'
os.environ['SPOTIPY_CLIENT_SECRET'] = '$MY_CLIENT_SECRET'
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 https://api.spotify.com/v1/playlists/7AatTbqsTPhQ4bTRDqXaQH/tracks with Params: {'position': None} returned 400 due to Invalid base62 id
Traceback (most recent call last):
  File ".../.venv/lib/python3.11/site-packages/spotipy/client.py", line 271, in _internal_call
    response.raise_for_status()
  File ".../.venv/lib/python3.11/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/7AatTbqsTPhQ4bTRDqXaQH/tracks

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/client.py", line 1085, in playlist_add_items
    return self._post(
           ^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/spotipy/client.py", line 328, in _post
    return self._internal_call("POST", url, payload, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/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/7AatTbqsTPhQ4bTRDqXaQH/tracks:
 Invalid base62 id, reason: None

 

 

 

Reply
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.

XimzendSpotify 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

Type a product name