Hi everyone I try to extract every song on a public playlist of a user at the begin everything goes ok but at some point throws me a error here is my code:
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
#Show tracks
def show_tracks(results):
for i, item in enumerate(results['items']):
track = item['track']
if track != None:
print("%d %s: %s" % (i, track['artists'][0]['name'], track['name']))
else:
pass
#Auth
client_credentials_manager = SpotifyClientCredentials(
client_id = '*****',
client_secret = '*****')
spotify = spotipy.Spotify(client_credentials_manager = client_credentials_manager)
#user = 'lucy.cgtz'
user = '1296791898'
playlists = spotify.user_playlists(user)
#Show the list and next show the tracks
while playlists:
for i, playlist in enumerate(playlists['items']):
print("%4d %s %s" % (i + 1 + playlists['offset'], playlist['uri'], playlist['name']))
results = spotify.user_playlist(user, playlist['id'], fields="tracks, next")
tracks = results['tracks']
show_tracks(tracks)
while tracks['next']:
tracks = spotify.next(tracks)
show_tracks(tracks)
#if playlists['next']:
# playlists = spotify.next(playlists)
#else:
# playlists = None
Throws me this error:
SpotifyException: https://api.spotify.com/v1/users/1296791898/playlists/1kAgnWp6dNhJukgUOJuLCo?fields=tracks%2C+next:
Not found.
The problem here is that playlist really exist any suggestions for this, thank you
It seems like the playlists of the user you're trying to fetch follows some playlists from other users. So, the original owner of the playlist in that case is not the user you specified but is the one who actually created the playlist.
Replacing user with playlist['owner']['id'] in
results = spotify.user_playlist(user, playlist['id'], fields="tracks, next")
should fix this.
Most helpful comment
It seems like the playlists of the user you're trying to fetch follows some playlists from other users. So, the original owner of the playlist in that case is not the user you specified but is the one who actually created the playlist.
Replacing
userwithplaylist['owner']['id']inshould fix this.