[GH-ISSUE #604] keyError when using get_playlist() #415

Closed
opened 2026-02-27 23:00:40 +03:00 by kerem · 9 comments
Owner

Originally created by @soreikomori on GitHub (Jun 21, 2024).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/604

Describe the bug
When attempting to run yt.get_playlist(), the program goes through all of the steps until it lands in line 97 of navigation.py, where it errors out:

root = root[k]
           ~^^^
KeyError: 'singleColumnBrowseResultsRenderer'

Just a moment ago, YTM seems to have pushed an update that makes playlists look different on browser. This random change might have caused some internal issue in the Google TV API that ytmusicapi fails to handle appropriately.

To Reproduce
Steps to reproduce the behavior:

  1. Use yt.get_playlist(), for example by running yt.get_playlist(id, None) where id is the ID of a playlist (string).
  2. Get the error.

Additional context
Here's how the entire error looks like for me.

Traceback (most recent call last):
  File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 323, in <module>
    initialize()
  File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 60, in initialize
    update()
  File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 282, in update
    cE.loadAllPlaylists()
  File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\compendium_engine.py", line 43, in loadAllPlaylists
    purgedPls = purgeFetchedPlaylist(yt.get_playlist(id, None)["tracks"]) # type: ignore
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 109, in get_playlist
    results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + ["musicPlaylistShelfRenderer"])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\navigation.py", line 103, in nav
    raise err
  File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\navigation.py", line 97, in nav
    root = root[k]
           ~~~~^^^
KeyError: 'singleColumnBrowseResultsRenderer'
Originally created by @soreikomori on GitHub (Jun 21, 2024). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/604 **Describe the bug** When attempting to run `yt.get_playlist()`, the program goes through all of the steps until it lands in line 97 of navigation.py, where it errors out: ``` root = root[k] ~^^^ KeyError: 'singleColumnBrowseResultsRenderer' ``` Just a moment ago, YTM seems to have pushed an update that makes playlists look different on browser. This random change might have caused some internal issue in the Google TV API that ytmusicapi fails to handle appropriately. **To Reproduce** Steps to reproduce the behavior: 1. Use `yt.get_playlist()`, for example by running `yt.get_playlist(id, None)` where id is the ID of a playlist (string). 2. Get the error. **Additional context** Here's how the entire error looks like for me. ``` Traceback (most recent call last): File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 323, in <module> initialize() File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 60, in initialize update() File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\user_console.py", line 282, in update cE.loadAllPlaylists() File "c:\Users\sorei\OneDrive\Miscellaneous\Applications\ReplayMix+\compendium_engine.py", line 43, in loadAllPlaylists purgedPls = purgeFetchedPlaylist(yt.get_playlist(id, None)["tracks"]) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 109, in get_playlist results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + ["musicPlaylistShelfRenderer"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\navigation.py", line 103, in nav raise err File "C:\Users\sorei\.pyenv\pyenv-win\versions\3.11.0b4\Lib\site-packages\ytmusicapi\navigation.py", line 97, in nav root = root[k] ~~~~^^^ KeyError: 'singleColumnBrowseResultsRenderer' ```
kerem 2026-02-27 23:00:40 +03:00
Author
Owner

@sigma67 commented on GitHub (Jun 21, 2024):

Can you please provide screenshots of the playlist format and response data (copy JSON response from network requests tab, from request to the playlist endpoint)

<!-- gh-comment-id:2182177365 --> @sigma67 commented on GitHub (Jun 21, 2024): Can you please provide screenshots of the playlist format and response data (copy JSON response from network requests tab, from request to the playlist endpoint)
Author
Owner

@scrimshander commented on GitHub (Jun 21, 2024):

I am a different user but exact same error. Playlist response JSON is attached. Not sure exactly what you are looking for re screenshot but I've attached the playlist page as it appears.

image

playlist_response.json

<!-- gh-comment-id:2182831560 --> @scrimshander commented on GitHub (Jun 21, 2024): I am a different user but exact same error. Playlist response JSON is attached. Not sure exactly what you are looking for re screenshot but I've attached the playlist page as it appears. <img width="1425" alt="image" src="https://github.com/sigma67/ytmusicapi/assets/5463111/1e01e011-d630-48d1-88aa-955200e9a04d"> [playlist_response.json](https://github.com/user-attachments/files/15928740/playlist_response.json)
Author
Owner

@sigma67 commented on GitHub (Jun 21, 2024):

Please tell which version of ytmusicapi you are using in case it isn't latest

<!-- gh-comment-id:2182923971 --> @sigma67 commented on GitHub (Jun 21, 2024): Please tell which version of ytmusicapi you are using in case it isn't latest
Author
Owner

@scrimshander commented on GitHub (Jun 21, 2024):

I was using 1.3.0 for the above. Didn't realize I was so far out of date. I just upgraded and am dealing with an issue that must be in my code but I will try to get it working and see what happens with the latest version.

<!-- gh-comment-id:2183024255 --> @scrimshander commented on GitHub (Jun 21, 2024): I was using 1.3.0 for the above. Didn't realize I was so far out of date. I just upgraded and am dealing with an issue that must be in my code but I will try to get it working and see what happens with the latest version.
Author
Owner

@JohnHKoh commented on GitHub (Jun 21, 2024):

Ran into the same issue using 0.25.2. Updated to the latest version (1.7.3) and now receiving the following error:

Traceback (most recent call last):
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 64, in to_int
    int_value = locale.atoi(number_string)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\locale.py", line 342, in atoi
    return int(delocalize(string))
           ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''

and

  File "C:\Users\asdf\Source\MelonYTMPlaylist\src\playlist_updater.py", line 117, in get_playlist
    return self.ytmusic.get_playlist(self.playlistId, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 111, in get_playlist
    return self._parse_new_playlist_format(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 215, in _parse_new_playlist_format
    song_count = to_int(song_count[0]) if len(song_count) > 1 else 0
                 ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 67, in to_int
    int_value = int(number_string)
                ^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
<!-- gh-comment-id:2183050213 --> @JohnHKoh commented on GitHub (Jun 21, 2024): Ran into the same issue using 0.25.2. Updated to the latest version (1.7.3) and now receiving the following error: ``` Traceback (most recent call last): File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 64, in to_int int_value = locale.atoi(number_string) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\locale.py", line 342, in atoi return int(delocalize(string)) ^^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '' ``` and ``` File "C:\Users\asdf\Source\MelonYTMPlaylist\src\playlist_updater.py", line 117, in get_playlist return self.ytmusic.get_playlist(self.playlistId, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 111, in get_playlist return self._parse_new_playlist_format( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 215, in _parse_new_playlist_format song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\asdf\AppData\Local\Programs\Python\Python311\Lib\site-packages\ytmusicapi\helpers.py", line 67, in to_int int_value = int(number_string) ^^^^^^^^^^^^^^^^^^ ValueError: invalid literal for int() with base 10: '' ```
Author
Owner

@soreikomori commented on GitHub (Jun 21, 2024):

I tried on 1.5.2 and 1.6.0 and got the same error on both. Upgrading to 1.7.3 seems to have fixed it fortunately. I'll leave the issue open for now though given what @JohnHKoh reported above.

<!-- gh-comment-id:2183068126 --> @soreikomori commented on GitHub (Jun 21, 2024): I tried on 1.5.2 and 1.6.0 and got the same error on both. Upgrading to 1.7.3 seems to have fixed it fortunately. I'll leave the issue open for now though given what @JohnHKoh reported above.
Author
Owner

@JohnHKoh commented on GitHub (Jun 21, 2024):

github.com/sigma67/ytmusicapi@11823d6387/ytmusicapi/mixins/playlists.py (L214-L215)

These seem to be the offending lines. I don't know what it looked like before, but second_subtitle_runs[has_views + 0]["text"] is "트랙 100개". Therefore song_count[0] now returns "트랙" (track) instead of "100개". This seems to be a localization issue, as when I change the language from Korean ("ko") to English ("en"), second_subtitle_runs[has_views + 0]["text"] is "100 tracks", and so song_count[0] now gets the correct value.

The code will need to be updated to extract the number from this string.

<!-- gh-comment-id:2183110336 --> @JohnHKoh commented on GitHub (Jun 21, 2024): https://github.com/sigma67/ytmusicapi/blob/11823d638719d76456ec58a6d7b76133368e5f1a/ytmusicapi/mixins/playlists.py#L214-L215 These seem to be the offending lines. I don't know what it looked like before, but `second_subtitle_runs[has_views + 0]["text"]` is "`트랙 100개`". Therefore `song_count[0]` now returns "트랙" (track) instead of "100개". This seems to be a localization issue, as when I change the language from Korean ("`ko`") to English ("`en`"), ``second_subtitle_runs[has_views + 0]["text"]`` is "`100 tracks`", and so `song_count[0]` now gets the correct value. The code will need to be updated to extract the number from this string.
Author
Owner

@sigma67 commented on GitHub (Jun 21, 2024):

I'm impressed that there are still people on 0.25. As it's fixed on latest I will close this thread.

<!-- gh-comment-id:2183130342 --> @sigma67 commented on GitHub (Jun 21, 2024): I'm impressed that there are still people on 0.25. As it's fixed on latest I will close this thread.
Author
Owner

@sigma67 commented on GitHub (Jun 21, 2024):

@JohnHKoh please create a separate issue as it is likely not directly related

<!-- gh-comment-id:2183133162 --> @sigma67 commented on GitHub (Jun 21, 2024): @JohnHKoh please create a separate issue as it is likely not directly related
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#415
No description provided.