n8henrie / pycookiecheat

Borrow cookies from your browser's authenticated session for use in Python scripts.
https://n8henrie.com/2013/11/use-chromes-cookies-for-easier-downloading-with-python-requests/
MIT License
744 stars 111 forks source link

pycookiecheat not working on Chrome 130 #76

Closed Shimada666 closed 2 weeks ago

Shimada666 commented 2 weeks ago

My Issue

Hi! I recently found that pycookiecheat is not working properly and throws the following exception:

➜  jq-notebook git:(master) ✗ pycookiecheat -v -v -v -v -v -v -u https://google.com -b Chrome
DEBUG:keyring.backend:Loading KWallet
DEBUG:keyring.backend:Loading SecretService
DEBUG:keyring.backend:Loading Windows
DEBUG:keyring.backend:Loading chainer
DEBUG:keyring.backend:Loading libsecret
DEBUG:keyring.backend:Loading macOS
b'c\\\xef\xf6\xf6b\xc7\xc6\xf9\x88\x97\\[\xb0\xc9?!\xc1\x1e\x84\x0c\x9av"\x81\x9bY\x0e\xcbM\xa3q49C382A82DF387414CE3007A99DEF08A:FG=1'
Traceback (most recent call last):
  File "/opt/homebrew/bin/pycookiecheat", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pycookiecheat/__main__.py", line 53, in main
    cookies = chrome_cookies(
              ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pycookiecheat/chrome.py", line 344, in chrome_cookies
    row["value"] = chrome_decrypt(
                   ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pycookiecheat/chrome.py", line 92, in chrome_decrypt
    return clean(decrypted)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pycookiecheat/chrome.py", line 54, in clean
    return decrypted[:-last].decode("utf8")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xef in position 2: invalid continuation byte

I suspect it might be related to the Chrome version, so I installed Chrome 129, and it works fine.

 ➜  jq-notebook git:(master) ✗ pycookiecheat -v -v -v -v -v -v -u https://google.com -b Chrome
DEBUG:keyring.backend:Loading KWallet
DEBUG:keyring.backend:Loading SecretService
DEBUG:keyring.backend:Loading Windows
DEBUG:keyring.backend:Loading chainer
DEBUG:keyring.backend:Loading libsecret
DEBUG:keyring.backend:Loading macOS
b'AVYB7cpM1ez0NX5TjwVkMoR8EEl5IVWmr780DV*********'
b'BcC3JtSuxU3kIPPF/AAMdM6*********'
b'AEesaJPHscoB*********'
...

Could you please take a look?

WHYT


Please make sure you've taken these steps before submitting a new issue:

n8henrie commented 2 weeks ago

Please try master -- a recent change in how chrome stores cookies

n8henrie commented 2 weeks ago

v0.8.0 was just released and may fix this -- please give it a shot and report back.

Shimada666 commented 2 weeks ago

@n8henrie Thanks! Now It works fine!

n8henrie commented 2 weeks ago

Glad to hear it!