[GH-ISSUE #191] get_artist_albums(channelId, params) returning KeyError: 'content' #147

Closed
opened 2026-02-27 22:08:17 +03:00 by kerem · 5 comments
Owner

Originally created by @MarkhorDev on GitHub (Apr 19, 2021).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/191

I'm trying to fetch a list of artist albums for artists with more albums than can be displayed in the get_artist() results. Sometimes it works, but other times I get:

Exception has occurred: KeyError
'content'
  File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 50, in get_album_list
    albums = ytm.get_artist_albums(channelID, params)
  File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 120, in get_album_data
    albumList = get_album_list(artistData)
  File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 38, in get_artist_data
    albumData = get_album_data(albumName, artistBrowseID = artistBrowseID, defaultIncluded = defaultIncluded)
  File "D:\Documents\Python\unfinished\bandThing\version4\scripts\main.py", line 6, in load_artist_to_csv
    artistData = ytm.get_artist_data(artistName, defaultIncluded = defaultIncluded)
  File "D:\Documents\Python\unfinished\bandThing\version4\scripts\main.py", line 152, in <module>
    load_artist_to_csv(artist, defaultIncluded = di)

I have tried looking at the original code but it is far too advanced for me. I have tried comparing data and found that the params variable is changing each time that I get it from get_artist() results, but don't know what is causing the error on certain calls, but not others.

Originally created by @MarkhorDev on GitHub (Apr 19, 2021). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/191 I'm trying to fetch a list of artist albums for artists with more albums than can be displayed in the get_artist() results. Sometimes it works, but other times I get: ``` Exception has occurred: KeyError 'content' File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 50, in get_album_list albums = ytm.get_artist_albums(channelID, params) File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 120, in get_album_data albumList = get_album_list(artistData) File "D:\Documents\Python\unfinished\bandThing\version4\scripts\ytmInteractor.py", line 38, in get_artist_data albumData = get_album_data(albumName, artistBrowseID = artistBrowseID, defaultIncluded = defaultIncluded) File "D:\Documents\Python\unfinished\bandThing\version4\scripts\main.py", line 6, in load_artist_to_csv artistData = ytm.get_artist_data(artistName, defaultIncluded = defaultIncluded) File "D:\Documents\Python\unfinished\bandThing\version4\scripts\main.py", line 152, in <module> load_artist_to_csv(artist, defaultIncluded = di) ``` I have tried looking at the original code but it is far too advanced for me. I have tried comparing data and found that the params variable is changing each time that I get it from get_artist() results, but don't know what is causing the error on certain calls, but not others.
kerem closed this issue 2026-02-27 22:08:17 +03:00
Author
Owner

@sigma67 commented on GitHub (Apr 19, 2021):

Could you kindly provide the channelId?

<!-- gh-comment-id:822825078 --> @sigma67 commented on GitHub (Apr 19, 2021): Could you kindly provide the channelId?
Author
Owner

@MarkhorDev commented on GitHub (Apr 19, 2021):

AC/DC: UCB0JSO6d5ysH2Mmqz5I9rIw
Anathema: UCD_YQdIsW1phqp5AqQwmKhg

get_artist_albums() is called in a function, called from a loop. It works if I try and do it on its own but it just breaks in the loop

<!-- gh-comment-id:822836475 --> @MarkhorDev commented on GitHub (Apr 19, 2021): AC/DC: UCB0JSO6d5ysH2Mmqz5I9rIw Anathema: UCD_YQdIsW1phqp5AqQwmKhg get_artist_albums() is called in a function, called from a loop. It works if I try and do it on its own but it just breaks in the loop
Author
Owner

@sigma67 commented on GitHub (Apr 20, 2021):

I can't replicate the error consistently either, but I see what you're referring to. I think it might be a timing issue, that get_artist_albums is being called too fast after get_artist and the server doesn't have the albums ready yet. Perhaps you can get more consistent results by adding a delay between the two calls?

But yea, it's just the server being flaky, not much we can do here on the ytmusicapi side imo.

<!-- gh-comment-id:823043500 --> @sigma67 commented on GitHub (Apr 20, 2021): I can't replicate the error consistently either, but I see what you're referring to. I think it might be a timing issue, that get_artist_albums is being called too fast after get_artist and the server doesn't have the albums ready yet. Perhaps you can get more consistent results by adding a delay between the two calls? But yea, it's just the server being flaky, not much we can do here on the ytmusicapi side imo.
Author
Owner

@MarkhorDev commented on GitHub (Apr 20, 2021):

I tried a few different delays and still got the issue with 3 seconds. Seemed to work fine with 5-second delays. Might just be a good idea to take out the loop and find a more efficient solution for what I'm trying to do. Thank you for your help.

<!-- gh-comment-id:823133138 --> @MarkhorDev commented on GitHub (Apr 20, 2021): I tried a few different delays and still got the issue with 3 seconds. Seemed to work fine with 5-second delays. Might just be a good idea to take out the loop and find a more efficient solution for what I'm trying to do. Thank you for your help.
Author
Owner

@sigma67 commented on GitHub (Apr 20, 2021):

To be honest this endpoint is quite awkward to work with, since it directly depends on another endpoint being called before. This clearly violates REST principles, where requests are supposed to be isolated, stateless and independent of each other.

But unfortunately it's all we have. Since there is no other way to access an official API, we have to work with it. Good luck in your endeavor.

<!-- gh-comment-id:823145112 --> @sigma67 commented on GitHub (Apr 20, 2021): To be honest this endpoint is quite awkward to work with, since it directly depends on another endpoint being called before. This clearly violates REST principles, where requests are supposed to be isolated, stateless and independent of each other. But unfortunately it's all we have. Since there is no other way to access an official API, we have to work with it. Good luck in your endeavor.
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/ytmusicapi#147
No description provided.