mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 16:45:52 +03:00
[GH-ISSUE #739] KeyError: 'items' #447
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#447
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ovcheric on GitHub (Nov 4, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/739
Trying to learn how to use Spotipy to create a text file with all songs and corresponding artist from a playlist.
When using the example "Playlist Tracks", I copied and pasted the code. When I run it, I get an error:
KeyError: 'items'I have the link to the playlist, and I have authorization access. I just dont understand how to pull information from the massive wall of text I get when getting information about songs in a playlist.
@Peter-Schorn commented on GitHub (Nov 4, 2021):
post the stack trace for the error.
@Ovcheric commented on GitHub (Nov 17, 2021):
Traceback (most recent call last): File "C:\Users\ovche\OneDrive\Desktop\Auto Spotify Playlist\AutoSpotifyPlaylist.py", line 49, in <module> playlist = sp.playlist_items(playlist_id)["items"] KeyError: 'items'@Ovcheric commented on GitHub (Dec 31, 2021):
If it helps, the error was in the fact that I was looking for 'items' in an array where that attribute did not exist.
I solved this issue by meticulously following along in the nested dictionary/list that you get when you do
pprint(sp.playlist_items(playlistID)).The CORRECT code if you are looking for the name of the track and artist is:
Name of the track at the top of the playlist:
sp.playlist_items(playlistID)['tracks']['items'][0]['track']['name']Artist of the track at the top of the playlist:
sp.playlist_items(playlistID)['tracks']['items'][0]['track']['artists'][0]['name']And if you want to iterate through the entire playlist, just use a for loop: