'Spotipy requests taking forever
I have been using Spotipy to get song data from a list of songs. It was working before, but suddenly the spotipy requests stopped finishing and the code is stuck. Any ideas what is going on?
def get_song_uri(row):
song = row['song']
artist = row['artist']
data_list = []
#Get song uri
print('search1')
res1 = sp.search(q='track:'+song+' artist:'+artist[:5],type='track')['tracks']['items']
print('search2')
if len(res1) == 0:
uri = pd.NA
for i in range(0,10): # Create a 10 feature vector of NA's
data_list.append(pd.NA)
else:
uri = res1[0]['uri']
print('b')
res2 = sp.audio_features(uri)[0] # Create a 10 feature vector of all the features (including URI)
data_list=[uri, res2['danceability'], res2['energy'], res2['loudness'], res2['speechiness'], res2['acousticness'], res2['instrumentalness'], res2['liveness'], res2['valence'], res2['tempo']]
print('Done')
return data_list
The code prints 'search1' but not 'search2', so I know it is stuck on the request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
