[Python] Getting Object of type "None" is not subscriptable error while using Spotify API to...

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Spotipy library to extract each song track information(e.g. album name, artist name) from Spotify playlist link. The code block below returns the output 'uris', but red wavy line on sp.playlist_tracks(playlist_id=playlist_uri)['items'] indicates an error message <Object of type "None" is not subscriptable>. I understand the error message itself, but cannot get a grip how this error message relates to my code. I tried to look at reportOptionalSubcript but doesn't seem like a solution for the root cause. Also tried printing output for each steps and see where the problem is stemming from but still need help.

    Any advice would be appreciated!

    My code:

    client_credentials_manager = SpotifyClientCredentials(client_id = client_id, client_secret= client_secret)

    sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)

    # Playlist link
    link = "https://open.spotify.com/playlist/37i9dQZF1DX2Zjg8kBuEsQ"
    # Get the URI of the playlist
    playlist_uri = link.split("/")[-1]

    # Get track information item for each track in the playlist
    uris = [x for x in sp.playlist_tracks(playlist_id=playlist_uri)['items']]

    Continue reading...

Compartilhe esta Página