Skip to content
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

Error 404 when calling playlist_items for Spotify's official "Top 50" playlist IDs #1175

Open
AdriaPadilla opened this issue Nov 30, 2024 · 19 comments · May be fixed by #1177
Open

Error 404 when calling playlist_items for Spotify's official "Top 50" playlist IDs #1175

AdriaPadilla opened this issue Nov 30, 2024 · 19 comments · May be fixed by #1177
Labels

Comments

@AdriaPadilla
Copy link

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

@mjanonis
Copy link

#1172

All Spotify-owned playlists are inaccessible using their API now https://developer.spotify.com/blog/2024-11-27-changes-to-the-web-api

@AdriaPadilla
Copy link
Author

You're absolutely right, I didn't pay full attention to Spotify post. It's very clear:

(...)
Effective today, new Web API use cases will no longer be able to access or use the following endpoints and functionality in their third-party applications.

  1. Algorithmic and Spotify-owned editorial playlists

(...)

Even so, a rather absurd decision by Spotify.

@akraus53
Copy link

akraus53 commented Dec 1, 2024

Thats so sad... I was copying a Spotify Artist Radio from one of the Artists from here into one of my playlists every day for the last year. Seems I have to find another way

@dieser-niko
Copy link
Member

I'm going to add this to the FAQ, this is going to throw off a lot of people.

@AdriaPadilla
Copy link
Author

I'm going to add this to the FAQ, this is going to throw off a lot of people.

I've been using the Top 50 playlists from European countries to understand the evolution of musical industry. Everything with an academic purpose, as I work at a university and we are deeply focused on cultural aspects. These playlists were a reflection of the evolution of the music market, but also of the cultural changes in the population.. From my point of view, it makes absolutely no sense to block access to these playlists via API... I wonder if the cost of the requests justifies the shutdown. Anyway, I think it's a pretty petty decision. I get that they don’t want to give access to audio_features, which is hidden info in the user interface and could be used to feed AI models... but how do these official playlists cause any harm?

@dieser-niko
Copy link
Member

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

@AdriaPadilla
Copy link
Author

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

@akraus53
Copy link

akraus53 commented Dec 4, 2024

I think in the age of information, every analysis done by someone (Spotify) is of interest to someone else (us) and therefore the creator doesn't want the user to have a benefit. If I were a competitor of Spotify, I'd also analyze the Top50 tracks or some other smart playlist, where Spotify spent time and engineering hours to create the algorithms.

It's really sad they felt the need to make these changes, on the other hand I can understand they don't want to offer their intellectual property (f&$king playlists) for free.

@Syzygianinfern0
Copy link

Does anyone have a workaround for getting public playlist tracks?

@dieser-niko
Copy link
Member

dieser-niko commented Dec 10, 2024

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"))

@Syzygianinfern0
Copy link

Just did! Can confirm that it works :D

@Syzygianinfern0
Copy link

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!

@dieser-niko
Copy link
Member

This is just a speculation and I'm not sure if this applies to all Spotify owned playlists, but if you decode the playlist id to ascii, then it stars off with the word "format". In the Base62 format that Spotify uses (0-9, a-z, A-Z) it starts like this: "37i9dQZF1EI". Maybe you could filter them like that.

@ParalysedBeaver
Copy link

I had a simple script that copied the contents of 2 Spotify owned Throwback Thursday playlists, as they constantly change and there were some weeks where I wanted a permeant copy. This change to the Spotify API broke it. Thank you, @dieser-niko, spotipy-anon got it working again.

@AdriaPadilla
Copy link
Author

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"))

OMG! It works perfectly. You’re a genius! I love it! Thank you so much!

I’ve tested it extensively using the sp.playlist_items(playlist_id) and sp.artist(artist_id) methods, with a time.sleep(1) between requests. Not a single API request was rejected.

Let’s not go too deep into this, so we don’t give Spotify ideas on how to close these doors.

From here, there are a few possibilities we should consider:

  1. Spotify might eventually block anonymous access to playlists and require OAuth.
  2. Spotify could introduce a very strict API requests limit for anonymous token.
  3. Spotify do nothing, and this could keep working.

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

In any case, once again, thank you so much!

@dieser-niko
Copy link
Member

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: #878 (comment)

@Syzygianinfern0
Copy link

This is just a speculation and I'm not sure if this applies to all Spotify owned playlists, but if you decode the playlist id to ascii, then it stars off with the word "format". In the Base62 format that Spotify uses (0-9, a-z, A-Z) it starts like this: "37i9dQZF1EI". Maybe you could filter them like that.

Not sure if that is right (a counter-example: Today's Top Hits)

@dieser-niko
Copy link
Member

dieser-niko commented Dec 11, 2024

Yeah, but when decoding the ID, it still starts with "format". You can use https://www.dcode.fr/base62-encoding to decode the ID if you want to try it out. Make sure to select 0-9a-zA-Z

@Syzygianinfern0
Copy link

Oh I understand now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants