[GH-ISSUE #275] current_user_playing_track(), current_playback() and currently_playing(): Cannot iterate through response: Data structure issue potentially? #149

Closed
opened 2026-02-27 23:21:05 +03:00 by kerem · 7 comments
Owner

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:
screen shot 2018-04-15 at 15 55 36

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.

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: ![screen shot 2018-04-15 at 15 55 36](https://user-images.githubusercontent.com/25749668/38779816-8f48a3e4-40c5-11e8-840b-38fe2f46f2b5.png) 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.
kerem closed this issue 2026-02-27 23:21:05 +03:00
Author
Owner

@ritiek commented on GitHub (Apr 16, 2018):

Is there a problem with indexing the artists list ['artists'][0]['name']?

<!-- gh-comment-id:381615470 --> @ritiek commented on GitHub (Apr 16, 2018): Is there a problem with indexing the artists list `['artists'][0]['name']`?
Author
Owner

@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:
screen shot 2018-04-16 at 15 49 06

<!-- gh-comment-id:381626087 --> @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: ![screen shot 2018-04-16 at 15 49 06](https://user-images.githubusercontent.com/25749668/38816322-bbec3ae6-418d-11e8-8f1d-05f9d930c375.png)
Author
Owner

@ritiek commented on GitHub (Apr 16, 2018):

@Dextroz No problem! Glad you figured out!

<!-- gh-comment-id:381626602 --> @ritiek commented on GitHub (Apr 16, 2018): @Dextroz No problem! Glad you figured out!
Author
Owner

@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

<!-- gh-comment-id:388969143 --> @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
Author
Owner

@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_playing and many more!

<!-- gh-comment-id:388970152 --> @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_playing` and many more!
Author
Owner

@discotwitch commented on GitHub (May 14, 2018):

@ritiek yup, that was the problem, thanks!

<!-- gh-comment-id:388978514 --> @discotwitch commented on GitHub (May 14, 2018): @ritiek yup, that was the problem, thanks!
Author
Owner

@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

<!-- gh-comment-id:388985465 --> @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](https://stackoverflow.com/questions/47028093/attributeerror-spotify-object-has-no-attribute-current-user-saved-tracks) I fixed it
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#149
No description provided.