Spotipy: Error while I extract the songs from every public playlist of a user

Created on 7 Nov 2017  路  1Comment  路  Source: plamere/spotipy

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

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 user with playlist['owner']['id'] in

results = spotify.user_playlist(user, playlist['id'], fields="tracks, next")

should fix this.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanRickli picture StefanRickli  路  3Comments

fortyTwo102 picture fortyTwo102  路  4Comments

gawaineo picture gawaineo  路  3Comments

Inspectiver picture Inspectiver  路  4Comments

mcurranseijo picture mcurranseijo  路  3Comments