I'm trying to pull audio features from spotify's API. I have a dataset with about 280,000 songs that don't contain the audio features I want so I'm pulling the track ID from each song on my dataset and sending a request in batches of 50 songs with a 1 second delay between requests. Yesterday I had no issue getting about 100,000 of those songs audio features but then it started throwing Error 429 which I know is the rate limit error. However, I've now waited a full day before calling again and now all I am getting is error 429 every time even when I change my batch size to 25 songs and a 5 second delay between requests.Curious if there's something in my code that is wrong thats making spotify's API not happy with me. All done in python.
#track_uri is column in my dataframe and I split it into track_id then turn into list and split into batches of 50 df['track_id'] = df['track_uri'].str.replace('spotify:track:', '', regex=False) track_ids = df['track_id'].tolist() batches = [track_ids[i:i + 50] for i in range(0, len(track_ids), 50)] ###token info def get_track_info(header, track_ids): ids = ','.join(track_ids) url = f'https://api.spotify.com/v1/audio-features/?ids={ids}' r = get(url, headers=header) return r.json() for i, batch in enumerate(batches, start=1): track_info = get_track_info(header, batch) filename = f'audio_features_{i}.json' with open(filename, 'w') as f: json.dump(track_info, f, indent=4) sleep(1)