[GH-ISSUE #423] KeyError: 'watchEndpoint' When Retrieving Artist Discography #318

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

Originally created by @skandallouz on GitHub (Aug 12, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/423

Describe the bug
While attempting to retrieve an artist's discography using the get_ytmusic_discography function, a KeyError related to the 'watchEndpoint' is encountered. This issue seems to occur specifically for artists with very large discographies, while it works normally for artists with small to medium-sized libraries. This prevents the successful retrieval of the artist information for those with extensive discographies.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize ytmusicapi with appropriate headers and setup.
  2. Call the get_ytmusic_discography function with valid ytmusic_artist_ids.
  3. Observe the KeyError related to 'watchEndpoint'.

Additional context
The error seems to be within the ytmusicapi library when trying to navigate through the response data. Here's a sample code and the error traceback:

(this is the code and error I'm getting)

def get_ytmusic_discography(ytmusic_artist_ids):
    discography = {}

    for ytmusic_artist_id in ytmusic_artist_ids:
        artist = ytmusic.get_artist(ytmusic_artist_id)
        print("Debugging Artist Info:", artist)
        artist_name = artist["name"]

        if 'albums' in artist:
            browseId = artist['albums']['browseId']
            params = artist['albums'].get('params', None)
            if params:
                album_data = ytmusic.get_artist_albums(browseId, params)
            else:
                album_data = artist['albums']['results']

            for album in album_data:
                discography[album['title']] = {
                    'url': 'https://music.youtube.com/' + album['browseId'],
                    'cover_art': album['thumbnails'][-1]['url'] if album['thumbnails'] else None
                }

        if 'singles' in artist:
            browseId = artist['singles']['browseId']
            params = artist['singles'].get('params', None)
            if params:
                single_data = ytmusic.get_artist_albums(browseId, params)
            else:
                single_data = artist['singles']['results']

            for single in single_data:
                discography[single['title']] = {
                    'url': 'https://music.youtube.com/' + single['browseId'],
                    'cover_art': single['thumbnails'][-1]['url'] if single['thumbnails'] else None
                }

    return discography, artist_name

# Error traceback:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 75, in nav
    root = root[k]
    ^^^^^^^
KeyError: 'watchEndpoint'

The code is attempting to retrieve discography information for specific artist IDs, but it encounters an issue within the ytmusicapi library. The error seems related to the internal parsing of the response data.

Originally created by @skandallouz on GitHub (Aug 12, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/423 **Describe the bug** While attempting to retrieve an artist's discography using the get_ytmusic_discography function, a KeyError related to the 'watchEndpoint' is encountered. This issue seems to occur specifically for artists with very large discographies, while it works normally for artists with small to medium-sized libraries. This prevents the successful retrieval of the artist information for those with extensive discographies. **To Reproduce** Steps to reproduce the behavior: 1. Initialize ytmusicapi with appropriate headers and setup. 2. Call the `get_ytmusic_discography` function with valid `ytmusic_artist_ids`. 3. Observe the `KeyError` related to `'watchEndpoint'`. **Additional context** The error seems to be within the `ytmusicapi` library when trying to navigate through the response data. Here's a sample code and the error traceback: (this is the code and error I'm getting) ```python def get_ytmusic_discography(ytmusic_artist_ids): discography = {} for ytmusic_artist_id in ytmusic_artist_ids: artist = ytmusic.get_artist(ytmusic_artist_id) print("Debugging Artist Info:", artist) artist_name = artist["name"] if 'albums' in artist: browseId = artist['albums']['browseId'] params = artist['albums'].get('params', None) if params: album_data = ytmusic.get_artist_albums(browseId, params) else: album_data = artist['albums']['results'] for album in album_data: discography[album['title']] = { 'url': 'https://music.youtube.com/' + album['browseId'], 'cover_art': album['thumbnails'][-1]['url'] if album['thumbnails'] else None } if 'singles' in artist: browseId = artist['singles']['browseId'] params = artist['singles'].get('params', None) if params: single_data = ytmusic.get_artist_albums(browseId, params) else: single_data = artist['singles']['results'] for single in single_data: discography[single['title']] = { 'url': 'https://music.youtube.com/' + single['browseId'], 'cover_art': single['thumbnails'][-1]['url'] if single['thumbnails'] else None } return discography, artist_name # Error traceback: File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ytmusicapi/navigation.py", line 75, in nav root = root[k] ^^^^^^^ KeyError: 'watchEndpoint' ``` The code is attempting to retrieve discography information for specific artist IDs, but it encounters an issue within the ytmusicapi library. The error seems related to the internal parsing of the response data.
kerem closed this issue 2026-02-27 23:00:09 +03:00
Author
Owner

@sigma67 commented on GitHub (Aug 12, 2023):

What is the value of ytmusic_artist_ids?

<!-- gh-comment-id:1675795839 --> @sigma67 commented on GitHub (Aug 12, 2023): What is the value of `ytmusic_artist_ids`?
Author
Owner

@skandallouz commented on GitHub (Aug 12, 2023):

Thank you for the quick response!
ytmusic_artist_ids = ['UC13ToEQgfmTe8_GW19LYtCg']
This ID corresponds to Udit Narayan, and I've encountered the KeyError related to the 'watchEndpoint' when working with his extensive discography as well as similar artists with large catalogs.

<!-- gh-comment-id:1675997726 --> @skandallouz commented on GitHub (Aug 12, 2023): Thank you for the quick response! ytmusic_artist_ids = ['UC13ToEQgfmTe8_GW19LYtCg'] This ID corresponds to Udit Narayan, and I've encountered the KeyError related to the 'watchEndpoint' when working with his extensive discography as well as similar artists with large catalogs.
Author
Owner

@sigma67 commented on GitHub (Aug 12, 2023):

I ran your code with the exact same setup and it worked fine. It must be an issue with your setup or a regional issue, which I can't help with.

<!-- gh-comment-id:1676104564 --> @sigma67 commented on GitHub (Aug 12, 2023): I ran your code with the exact same setup and it worked fine. It must be an issue with your setup or a regional issue, which I can't help with.
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#318
No description provided.