Why isn't the spotipy artist(uid) function working?

64 Views Asked by At

I'm trying to get the full artist object using the artist id that can be found in a track, but when I run my code, it doesn't work. Not only does artist(artist_id) not work, but I tested artist_albums(artist id) and artist_top_tracks(artist id) to see if it was an issue with that particular function, but they also failed to work, and the code only stalled. Thinking I might have gotten an invalid artist id from other parts of my code, I tried using the one found in the Spotify documentation(Pitbull's artist id) but the same thing happened. I have no issue parsing a user's saved tracks, though, so I'm unsure what exactly the problem is. Is there an issue on Spotipy's side or is this something wrong with my code? For reference, all the code below except the last line does what it's meant to do:

track_id = song['track']['id']
track_artist = song['track']['artists'][0]
artist_name = track_artist['name']
artist_id = track_artist['id']
artist = sp.artist(artist_id)
1

There are 1 best solutions below

0
On

Heres a method I used to get all info from an album, and I added your artist id logic. It worked successfully:

all_info = sp.album_tracks(album_id=playlist_id, limit=50)
t = 0
for idr, m in enumerate(all_info['items']):
   track = m['name']
   track_id = m['id']
   track_name =  m['name'] + " by " + m['artists'][0]['name']
   artist_id = m['artists'][0]['id']
   artist = sp.artist(artist_id)
   print(artist)

This printed a JSON with the artist object. I can't see exactly which method you're using from Spotipy to get the artist id since you did not specify. If you provide more code, I could perhaps help find your bug.