ytmusicapi icon indicating copy to clipboard operation
ytmusicapi copied to clipboard

Breaking value in Chrome cookie for auth

Open scrimshander opened this issue 1 year ago • 1 comments

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.

scrimshander avatar Sep 15 '22 20:09 scrimshander

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.

sigma67 avatar Sep 21 '22 12:09 sigma67

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

JohnHKoh avatar Oct 13 '22 13:10 JohnHKoh