[GH-ISSUE #71] get_library_upload_songs() throws KeyError if there are no uploaded songs #52

Closed
opened 2026-02-27 22:07:46 +03:00 by kerem · 2 comments
Owner

Originally created by @apastel on GitHub (Sep 1, 2020).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/71

Originally assigned to: @apastel on GitHub.

get_library_upload_albums() returns an empty list when there are no uploaded albums.

But get_library_upload_songs() and get_library_upload_artists() both throw a KeyError if either of them are empty.

I propose that they also return an empty list for consistency and ease of error handling.

>>> from ytmusicapi import YTMusic
>>> youtube_auth = YTMusic('headers_auth.json')
>>> youtube_auth.get_library_upload_albums()
[]
>>> youtube_auth.get_library_upload_songs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/apastel/dev/ytmusic-deleter/venv/lib/python3.6/site-packages/ytmusicapi/mixins/uploads.py", line 36, in get_library_upload_songs
    results = nav(results, ITEM_SECTION)['musicShelfRenderer']
KeyError: 'musicShelfRenderer'
>>> youtube_auth.get_library_upload_artists()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/apastel/dev/ytmusic-deleter/venv/lib/python3.6/site-packages/ytmusicapi/mixins/uploads.py", line 93, in get_library_upload_artists
    results = nav(results, ITEM_SECTION)['musicShelfRenderer']
KeyError: 'musicShelfRenderer'
Originally created by @apastel on GitHub (Sep 1, 2020). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/71 Originally assigned to: @apastel on GitHub. `get_library_upload_albums()` returns an empty list when there are no uploaded albums. But `get_library_upload_songs()` and `get_library_upload_artists()` both throw a KeyError if either of them are empty. I propose that they also return an empty list for consistency and ease of error handling. ``` >>> from ytmusicapi import YTMusic >>> youtube_auth = YTMusic('headers_auth.json') >>> youtube_auth.get_library_upload_albums() [] >>> youtube_auth.get_library_upload_songs() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/apastel/dev/ytmusic-deleter/venv/lib/python3.6/site-packages/ytmusicapi/mixins/uploads.py", line 36, in get_library_upload_songs results = nav(results, ITEM_SECTION)['musicShelfRenderer'] KeyError: 'musicShelfRenderer' >>> youtube_auth.get_library_upload_artists() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/apastel/dev/ytmusic-deleter/venv/lib/python3.6/site-packages/ytmusicapi/mixins/uploads.py", line 93, in get_library_upload_artists results = nav(results, ITEM_SECTION)['musicShelfRenderer'] KeyError: 'musicShelfRenderer' ```
kerem 2026-02-27 22:07:46 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@sigma67 commented on GitHub (Sep 1, 2020):

Good point, do you want to tackle this?

<!-- gh-comment-id:684619822 --> @sigma67 commented on GitHub (Sep 1, 2020): Good point, do you want to tackle this?
Author
Owner

@apastel commented on GitHub (Sep 1, 2020):

I might be able to, yes.

<!-- gh-comment-id:684983275 --> @apastel commented on GitHub (Sep 1, 2020): I might be able to, yes.
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#52
No description provided.