[GH-ISSUE #436] get_charts is having KeyError #327

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

Originally created by @ankydv on GitHub (Sep 23, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/436

[1.2.1/1.1.1] get_charts is having KeyError: -

To Reproduce
Steps to reproduce the behavior:

  1. Comment this section in explore.py since it's having KeyError, I'm unable to figure out.. Hence to avoid this error:-
charts['countries']['options'] = list(
             filter(None, [
                 nav(m, ['payload', 'musicFormBooleanChoice', 'opaqueToken'], True)
                 for m in nav(response, FRAMEWORK_MUTATIONS)
             ]))
  1. Call the get_charts function (auth or without auth).

Additional context
With some analysis I've figured out that youtube returns different response for different videos.
It appears to only occurs in 'videos' section. Not 'trending'.

**Cause
The NAVIGATION_VIDEO_ID in navigation.py is not sufficient to cover all types of responses from Youtube as the reponse of Youtube is inconsistent.

Expected structure of response:-

'navigationEndpoint':  {
					"clickTrackingParams": "CL0JEKCzAhgAIhMImaOrk6rAgQMVq8JzAR3dbAig",
					"watchEndpoint": {
						"videoId": "RLzC55ai0eo",
						"playlistId": "PL4fGSI1pDJn40WjZ6utkIuj2rNg-7iGsq",
						"loggingContext": {
							"vssLoggingContext": {
								"serializedContextData": "GiJQTDRmR1NJMXBESm40MFdqWjZ1dGtJdWoyck5nLTdpR3Nx"
							}
						},
						"watchEndpointMusicSupportedConfigs": {
							"watchEndpointMusicConfig": {
								"musicVideoType": "MUSIC_VIDEO_TYPE_OMV"
							}
						}
					}

In some cases, the response is like: -

'navigationEndpoint': {
					"clickTrackingParams": "CLEJEKCzAhgBIhMImaOrk6rAgQMVq8JzAR3dbAig",
					"browseEndpoint": {
						"browseId": "MPEDVAdGW7QDJiU",
						"params": "ggMnmgEkCiJQTDRmR1NJMXBESm40MFdqWjZ1dGtJdWoyck5nLTdpR3Nx",
						"browseEndpointContextSupportedConfigs": {
							"browseEndpointContextMusicConfig": {
								"pageType": "MUSIC_PAGE_TYPE_NON_MUSIC_AUDIO_TRACK_PAGE"
							}
						}
					}
				}


				}

Possible solution

In those cases, the video ID exists somewhere else, not in 'navigationEndpoint', the navigation should be like: -
NAVIGATION_VIDEO_ID_2 = ['menu','menuRenderer','items',0,'menuServiceItemRenderer','serviceEndpoint','queueAddEndpoint','queueTarget','videoId']

Hence we could fix it by excepting the KeyError with this nav instead.

Error.txt

Originally created by @ankydv on GitHub (Sep 23, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/436 ### [1.2.1/1.1.1] get_charts is having KeyError: - **To Reproduce** Steps to reproduce the behavior: 1. Comment this section in explore.py since it's having KeyError, I'm unable to figure out.. Hence to avoid this error:- ``` charts['countries']['options'] = list( filter(None, [ nav(m, ['payload', 'musicFormBooleanChoice', 'opaqueToken'], True) for m in nav(response, FRAMEWORK_MUTATIONS) ])) ``` 1. Call the get_charts function (auth or without auth). **Additional context** With some analysis I've figured out that youtube returns different response for different videos. It appears to only occurs in 'videos' section. Not 'trending'. **Cause The NAVIGATION_VIDEO_ID in navigation.py is not sufficient to cover all types of responses from Youtube as the reponse of Youtube is inconsistent. Expected structure of response:- ``` 'navigationEndpoint': { "clickTrackingParams": "CL0JEKCzAhgAIhMImaOrk6rAgQMVq8JzAR3dbAig", "watchEndpoint": { "videoId": "RLzC55ai0eo", "playlistId": "PL4fGSI1pDJn40WjZ6utkIuj2rNg-7iGsq", "loggingContext": { "vssLoggingContext": { "serializedContextData": "GiJQTDRmR1NJMXBESm40MFdqWjZ1dGtJdWoyck5nLTdpR3Nx" } }, "watchEndpointMusicSupportedConfigs": { "watchEndpointMusicConfig": { "musicVideoType": "MUSIC_VIDEO_TYPE_OMV" } } } ``` In some cases, the response is like: - ``` 'navigationEndpoint': { "clickTrackingParams": "CLEJEKCzAhgBIhMImaOrk6rAgQMVq8JzAR3dbAig", "browseEndpoint": { "browseId": "MPEDVAdGW7QDJiU", "params": "ggMnmgEkCiJQTDRmR1NJMXBESm40MFdqWjZ1dGtJdWoyck5nLTdpR3Nx", "browseEndpointContextSupportedConfigs": { "browseEndpointContextMusicConfig": { "pageType": "MUSIC_PAGE_TYPE_NON_MUSIC_AUDIO_TRACK_PAGE" } } } } } ``` **Possible solution** In those cases, the video ID exists somewhere else, not in 'navigationEndpoint', the navigation should be like: - NAVIGATION_VIDEO_ID_2 = ['menu','menuRenderer','items',0,'menuServiceItemRenderer','serviceEndpoint','queueAddEndpoint','queueTarget','videoId'] Hence we could fix it by excepting the KeyError with this nav instead. [Error.txt](https://github.com/sigma67/ytmusicapi/files/12706190/Error.txt)
kerem 2026-02-27 23:00:12 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@sigma67 commented on GitHub (Sep 23, 2023):

Which region are you looking at? Please specify the failing call in more detail. If it's the default region for you please figure out which one that is.

<!-- gh-comment-id:1732349208 --> @sigma67 commented on GitHub (Sep 23, 2023): Which region are you looking at? Please specify the failing call in more detail. If it's the default region for you please figure out which one that is.
Author
Owner

@ankydv commented on GitHub (Sep 23, 2023):

I checked for default region as well as my region ('IN"). In both the cases there was the same issue. You could look the 'Error.txt' file that I have already dropped.

<!-- gh-comment-id:1732357384 --> @ankydv commented on GitHub (Sep 23, 2023): I checked for default region as well as my region ('IN"). In both the cases there was the same issue. You could look the 'Error.txt' file that I have already dropped.
Author
Owner

@Arnav717 commented on GitHub (Sep 24, 2023):

I am also facing the same issue,
for "ZZ" region as well as for "IN" region its giving keyError.

<!-- gh-comment-id:1732653669 --> @Arnav717 commented on GitHub (Sep 24, 2023): I am also facing the same issue, for "ZZ" region as well as for "IN" region its giving keyError.
Author
Owner

@ankydv commented on GitHub (Sep 25, 2023):

I've the solution, I could raise a pull request.

<!-- gh-comment-id:1732842505 --> @ankydv commented on GitHub (Sep 25, 2023): I've the solution, I could raise a pull request.
Author
Owner

@Arnav717 commented on GitHub (Sep 25, 2023):

I've the solution, I could raise a pull request.

Yes please PR it
also whats the solution to this?

<!-- gh-comment-id:1733112141 --> @Arnav717 commented on GitHub (Sep 25, 2023): > I've the solution, I could raise a pull request. Yes please PR it also whats the solution to this?
Author
Owner

@ankydv commented on GitHub (Sep 25, 2023):

I've the solution, I could raise a pull request.

Yes please PR it also whats the solution to this?

I've Created a PR. You could view it.

<!-- gh-comment-id:1734038163 --> @ankydv commented on GitHub (Sep 25, 2023): > > I've the solution, I could raise a pull request. > > Yes please PR it also whats the solution to this? I've Created a PR. You could view it.
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#327
No description provided.