mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 08:35:49 +03:00
[GH-ISSUE #275] current_user_playing_track(), current_playback() and currently_playing(): Cannot iterate through response: Data structure issue potentially? #149
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#149
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 @ghost on GitHub (Apr 15, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/275
When using current_user_playing_track(), current_playback() and currently_playing() all 3 responses return a dict which is fine. However, the issue lies when I try to pull information about the artist.

Example response:
For each function response, when I pull the 'artists' key. It is a list data structure; even though it also has dictionary syntax inside of it. So my question is, why is it a list and not just a nested dictionary like the rest of the response. The list data structure makes it extremely difficult to pull information, as the 'list' cannot be iterated through as it is seen by Python as being one large list entry.
I can pull the album name and track name easily as they are not inside a list within the response however, I cannot get the artist name due to this problem.
I am using the latest version of Spotipy. Downloaded and unpacked from repo download.
@ritiek commented on GitHub (Apr 16, 2018):
Is there a problem with indexing the artists list
['artists'][0]['name']?@ghost commented on GitHub (Apr 16, 2018):
Oh for goodness sake, very noob mistake by me. You're solution works. Even more noob mistake is that I have used that indexing in my project before; this solution completely slipped my mind. Thank you @ritiek. Shows how I should have looked at my previous work to find a solution first before opening an issue. Many Thanks. Closed.
The code:

@ritiek commented on GitHub (Apr 16, 2018):
@Dextroz No problem! Glad you figured out!
@discotwitch commented on GitHub (May 14, 2018):
when I use currently_playing it says "Spotify has no attribute currently_playing". What am I doing wrong?
I'm using spotipy v2.4.4
@ritiek commented on GitHub (May 14, 2018):
@migel210 Hi, you're probably using the older version on PyPi. You can install the latest development version as mentioned here https://github.com/plamere/spotipy/issues/211#issuecomment-369863112. You should then be able to use newer unreleased methods like
currently_playingand many more!@discotwitch commented on GitHub (May 14, 2018):
@ritiek yup, that was the problem, thanks!
@discotwitch commented on GitHub (May 14, 2018):
@ritiek sorry, how exactly do you download the dev version?
when I clone the rep and do install setup.py I get an error "package directory 'spotipy' doesnt exist"
Edit: after referring to this I fixed it