[GH-ISSUE #294] Breaking value in Chrome cookie for auth #231

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

Originally created by @scrimshander on GitHub (Sep 15, 2022).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/294

Just had to refresh my auth headers after many many months, and kept getting a missing key bug in the cookie, pasted from Chrome/developer tools.

Turns out this key/value:

YT_CL={\"loctok\":\"APLXd64Le9G-vJVqzKjy-OsOVBh6NfU2xKnD6awbKB9lJUXzvHGMuNBmjOpK5q_K xVqxgIRcjI_FC27tj-wmyhvUgW8g4A\"};

Was breaking the cookie parser (perhaps because of the quotes or the embedded dict). Removing it from the headers text fixed the issue.

Originally created by @scrimshander on GitHub (Sep 15, 2022). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/294 Just had to refresh my auth headers after many many months, and kept getting a missing key bug in the cookie, pasted from Chrome/developer tools. Turns out this key/value: `YT_CL={\"loctok\":\"APLXd64Le9G-vJVqzKjy-OsOVBh6NfU2xKnD6awbKB9lJUXzvHGMuNBmjOpK5q_K xVqxgIRcjI_FC27tj-wmyhvUgW8g4A\"};` Was breaking the cookie parser (perhaps because of the quotes or the embedded dict). Removing it from the headers text fixed the issue.
kerem closed this issue 2026-02-27 22:08:43 +03:00
Author
Owner

@sigma67 commented on GitHub (Sep 21, 2022):

This seems strange, your cookie value is not escaped properly. Can you please paste the original YT_CL headers from Chrome? Excluding the identifying Cookie entry and any private information in there, it's not relevant here.

<!-- gh-comment-id:1253614213 --> @sigma67 commented on GitHub (Sep 21, 2022): This seems strange, your cookie value is not escaped properly. Can you please paste the original `YT_CL` headers from Chrome? Excluding the identifying `Cookie` entry and any private information in there, it's not relevant here.
Author
Owner

@JohnHKoh commented on GitHub (Oct 13, 2022):

Same issue here - in the Chrome DevTools, the cookie looks like:

YT_CL={"loctok":"stringofchars"};

Before, I was receiving the error: "Exception: Your cookie is missing the required value __Secure-3PAPISID". But after removing the "YT_CL" cookie, it started to work again.

It seems to be an issue with the way SimpleCookie loads raw data. It does not seem to handle quotes properly.

>>> from http.cookies import SimpleCookie
>>> SimpleCookie('a1={b:c};')   
<SimpleCookie: a1='{b:c}'>
>>> SimpleCookie('a1={"b":c};')
<SimpleCookie: >
>>> SimpleCookie('a1={\"b\":c};') 
<SimpleCookie: >

See this long-standing open bug report:
https://github.com/python/cpython/issues/71861

<!-- gh-comment-id:1277606021 --> @JohnHKoh commented on GitHub (Oct 13, 2022): Same issue here - in the Chrome DevTools, the cookie looks like: ``` YT_CL={"loctok":"stringofchars"}; ``` Before, I was receiving the error: "Exception: Your cookie is missing the required value __Secure-3PAPISID". But after removing the "YT_CL" cookie, it started to work again. It seems to be an issue with the way `SimpleCookie` loads raw data. It does not seem to handle quotes properly. ``` >>> from http.cookies import SimpleCookie >>> SimpleCookie('a1={b:c};') <SimpleCookie: a1='{b:c}'> >>> SimpleCookie('a1={"b":c};') <SimpleCookie: > >>> SimpleCookie('a1={\"b\":c};') <SimpleCookie: > ``` See this long-standing open bug report: https://github.com/python/cpython/issues/71861
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#231
No description provided.