spotipy: Error 404 when calling playlist_items for Spotify's official "Top 50" playlist IDs

Hello!

I’m encountering an issue when using the playlist_items() function from Spotipy to retrieve tracks from Spotify’s official “Top 50” playlists. I tested the code with multiple playlist IDs, all corresponding to Spotify’s public official playlists, and encountered the same problem consistently.

For example, the API returns 404 for all this playlist ids:

COUNTRY ID Playlist Name
Bolivia 37i9dQZEVXbJqfMFK4d691 Top 50: Bolivia
Brazil 37i9dQZEVXbMXbN3EUUhlg Top 50: Brazil
Bulgaria 37i9dQZEVXbNfM2w2mq1B8 Top 50: Bulgaria
Canada 37i9dQZEVXbKj23U1GF4IR Top 50: Canada

The code


import json
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

client_credentials_manager = SpotifyClientCredentials(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET'
)
spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)


def get_playlist_data():
    playlist_id = "37i9dQZEVXbMnz8KIWsvf9"
    api_response = spotify.playlist_items(playlist_id)
    with open(f"{playlist_id}.json", 'w', encoding='utf-8') as f:
        json.dump(api_response, f, ensure_ascii=False, indent=4)


print("Getting Playlist Data")
get_playlist_data()

API returns:

HTTP Error for GET to https://api.spotify.com/v1/playlists/37i9dQZEVXbJqfMFK4d691/tracks with Params: {'limit': 100, 'offset': 0, 'fields': None, 'market': None, 'additional_types': 'track,episode'} returned 404 due to Resource not found

(... Traceback)

spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/playlists/37i9dQZEVXbJqfMFK4d691/tracks?limit=100&offset=0&additional_types=track%2Cepisode:
Resource not found, reason: None

However, it works perfectly when using a public playlist ID created by users. For example, the code works flawlessly with this Queen playlist: 2sWWEDq1DuOnAJJWVHMRfC.

This indicates that the issue is not with my code but with the API itself.

I have searched for information in Spotify’s API documentation and announcements but found no mention of any restrictions related to this. Has anyone else encountered the same issue? Perhaps it might be necessary to escalate this to Spotify to understand what is happening. Any insights or information would be greatly appreciated.

Spotipy Version: 2.24.0 Python Version: 3.12.3 Operating System: Ubuntu 24.04.1 LTS x86_64

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 24 (8 by maintainers)

Most upvoted comments

Honestly I can’t believe this, but my project spotipy-anon is not yet affected by this change. It might get patched in the future though. Here’s a quick code snippet to try it out yourself:

pip install spotipy-anon
import spotipy
from spotipy_anon import SpotifyAnon

sp = spotipy.Spotify(auth_manager=SpotifyAnon())

print(sp.playlist("37i9dQZF1DXcBWIGoYBM5M"))

Maybe we should suggest officially incorporating SpotifyAnon into Spotipy and adding specific methods for making anonymous requests to Spotify-owned objects.

The thing is, spotipy-anon uses an unofficial and undocumented endpoint, so it doesn’t really fit in. I actually requested this before I became a member and was denied for the same reason, which I do agree with: https://github.com/spotipy-dev/spotipy/issues/878#issuecomment-1299996552

@Syzygianinfern0 what doesn’t work for you? I still can fetch Spotify’s playlists.

My current workaround is to use two different Spotipy auths like this

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(id, secret, "http://example.com", scope=scope))
sp_anon = spotipy.Spotify(auth_manager=SpotifyAnon())

I use sp to read/write on my playlists and sp_anon to read public playlists!

@AdriaPadilla Reply to this post on Spotify’s forum if you haven’t done so already: https://community.spotify.com/t5/Spotify-for-Developers/Changes-to-Web-API/td-p/6540414

I’m not sure if this will change anything, but your comment would fit right in.

Done!

I’ve read some responses to the post on Spotify’s official page, and the change is catastrophic for many developers. I’ve also seen numerous students with their final projects ruined, as well as academics (myself included) who used the API to access specific data. This decision is unacceptable.

@AdriaPadilla Reply to this post on Spotify’s forum if you haven’t done so already: https://community.spotify.com/t5/Spotify-for-Developers/Changes-to-Web-API/td-p/6540414

I’m not sure if this will change anything, but your comment would fit right in.