Announcements

Help Wizard

Step 1

NEXT STEP

Rate Limiting: 429 Error only associated with Audio Features

Rate Limiting: 429 Error only associated with Audio Features

Windows - Python API

 

Running into a frustrating issue. I am being hit with a 429 error when attempting to request Audio features for a specific song. Not a bunch of API calls, but literally just a single one will give me this error. 

 

I am able to make other calls, for example in the below code I search for the artist ID, get a list of their top songs, but then when I select a single song to get audio features for, i get hit with 429 error. I have tested this in a few different scripts and always the same. Everything works fine, but the second i request audio features, BAM! rate limit problem.. I saw some other posts on the internet discussing the same problem, but not solutions presented. Only thing i can think of is just wait a bit and see if that helps, although what a frustrating solution. 

 

def get_top_tracks(artist_name😞
    results = sp.search(q='artist:' + artist_name, type='artist')
    artist_id = results['artists']['items'][0]['id']
    tracks = sp.artist_top_tracks(artist_id)
    return [(track['name'], track['id']) for track in tracks['tracks']]

def display_track_info(track_id😞
    print("\nFetching track details...")
    track_info = sp.track(track_id)
    print(f"Name: {track_info['name']}")
    print(f"Album: {track_info['album']['name']}")
    print(f"Release Date: {track_info['album']['release_date']}")
    print(f"Popularity: {track_info['popularity']}")

def display_audio_features(track_id😞
    print("\nFetching audio features...")
    features = sp.audio_features([track_id])[0]
    if features:
        print(f"Danceability: {features['danceability']}")
        print(f"Energy: {features['energy']}")
        print(f"Key: {features['key']}")
        print(f"Loudness: {features['loudness']}")
        print(f"Mode: {features['mode']}")
        print(f"Speechiness: {features['speechiness']}")
        print(f"Acousticness: {features['acousticness']}")
        print(f"Instrumentalness: {features['instrumentalness']}")
        print(f"Liveness: {features['liveness']}")
        print(f"Valence: {features['valence']}")
        print(f"Tempo: {features['tempo']}")
        print(f"Duration (ms): {features['duration_ms']}")
        print(f"Time Signature: {features['time_signature']}")
    else:
        print("No audio features found for this track.")
       
def display_audio_analysis_part(track_id, part😞
    print(f"\nFetching audio analysis for {part}...")
    analysis = sp.audio_analysis(track_id)
    if part in analysis:
        for item in analysis[part]:
            print(item)
    else:
        print("Invalid part of audio analysis.")

def analyze_track(track_id😞
    while True:
        choice = input("\nChoose an option: \n1. Segments\n2. Bars\n3. Beats\n4. Tatums\n5. Sections\n6. Audio Features\n7. Exit\n> ")
        if choice in ['1', '2', '3', '4', '5']:
            parts = ['segments', 'bars', 'beats', 'tatums', 'sections']
            display_audio_analysis_part(track_id, parts[int(choice) - 1])
        elif choice == '6':
            display_audio_features(track_id)
        elif choice == '7':
            break
        else:
            print("Invalid option, please try again.")

# Main interaction
artist_name = input("Enter the name of the artist: ")
tracks = get_top_tracks(artist_name)

print(f"\nTop tracks of {artist_name}:")
for i, (name, _) in enumerate(tracks, 1😞
    print(f"{i}. {name}")

track_choice = int(input("\nEnter the number of the track you want to explore: "))
selected_track_id = tracks[track_choice - 1][1]

display_track_info(selected_track_id)
analyze_track(selected_track_id)
Reply
1 Reply

Same issue here. Only affects "audio features". It looks like this has been an issue for years though, and I haven't seen a response from Spotify solving it.

Suggested posts