[GH-ISSUE #451] KeyError: 'contents' when searching for a song #336

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

Originally created by @ranile on GitHub (Oct 6, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/451

Describe the bug
Searching for a song fails with KeyError: 'contents'

To Reproduce

from ytmusicapi import YTMusic

ytmusic = YTMusic('browser.json')

ytmusic.search('end of a life', filter='songs', scope='library', ignore_spelling=True)

Stacktrace

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    ytmusic.search('end of a life', filter='songs', scope='library', ignore_spelling=True)
  File "venv/lib/python3.11/site-packages/ytmusicapi/mixins/search.py", line 178, in search
    results = nav(results, SECTION_LIST)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 83, in nav
    raise err
  File "venv/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 77, in nav
    root = root[k]
           ~~~~^^^
KeyError: 'contents'
Originally created by @ranile on GitHub (Oct 6, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/451 **Describe the bug** Searching for a song fails with `KeyError: 'contents'` **To Reproduce** ```python from ytmusicapi import YTMusic ytmusic = YTMusic('browser.json') ytmusic.search('end of a life', filter='songs', scope='library', ignore_spelling=True) ``` **Stacktrace** ``` Traceback (most recent call last): File "main.py", line 5, in <module> ytmusic.search('end of a life', filter='songs', scope='library', ignore_spelling=True) File "venv/lib/python3.11/site-packages/ytmusicapi/mixins/search.py", line 178, in search results = nav(results, SECTION_LIST) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "venv/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 83, in nav raise err File "venv/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 77, in nav root = root[k] ~~~~^^^ KeyError: 'contents' ```
kerem closed this issue 2026-02-27 23:00:15 +03:00
Author
Owner

@sigma67 commented on GitHub (Oct 7, 2023):

This is library search, can you please post a screenshot of what that search result looks like for you in the Web UI.

And a JSON of the server response, if possible.

<!-- gh-comment-id:1751709197 --> @sigma67 commented on GitHub (Oct 7, 2023): This is library search, can you please post a screenshot of what that search result looks like for you in the Web UI. And a JSON of the server response, if possible.
Author
Owner

@ranile commented on GitHub (Oct 7, 2023):

Can you provide the code to make a fetch request for the endpoint that's being called? I can make the fetch request from the console and give you the response.

If the request is something the UI makes, Firefox lets you copy the request as fetch from the network tab in the dev tools

<!-- gh-comment-id:1751709886 --> @ranile commented on GitHub (Oct 7, 2023): Can you provide the code to make a fetch request for the endpoint that's being called? I can make the fetch request from the console and give you the response. If the request is something the UI makes, Firefox lets you copy the request as fetch from the network tab in the dev tools
Author
Owner

@sigma67 commented on GitHub (Oct 7, 2023):

You can just replicate the search request on the Web UI and copy the response as you would when copying auth credentials (though response, not request headers in this case).

https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html#copy-authentication-headers

<!-- gh-comment-id:1751741475 --> @sigma67 commented on GitHub (Oct 7, 2023): You can just replicate the search request on the Web UI and copy the response as you would when copying auth credentials (though response, not request headers in this case). https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html#copy-authentication-headers
Author
Owner

@ranile commented on GitHub (Oct 9, 2023):

It must've been some weird A/B thing google did? I just tried again and now it works. Thanks for the help and making this library

<!-- gh-comment-id:1752952998 --> @ranile commented on GitHub (Oct 9, 2023): It must've been some weird A/B thing google did? I just tried again and now it works. Thanks for the help and making this library
Author
Owner

@sigma67 commented on GitHub (Oct 9, 2023):

Google A/B tests, the bane of my existence. Thanks for reporting back!

<!-- gh-comment-id:1753378948 --> @sigma67 commented on GitHub (Oct 9, 2023): Google A/B tests, the bane of my existence. Thanks for reporting back!
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#336
No description provided.