pycookiecheat: UnicodeDecodeError: 'utf-8' codec can't decode byte in `clean` function

Hi, @n8henrie , I found this error when I use pycookiecheat

my machine version info: Linux version 4.9.43-1-MANJARO (builduser@manjaro) (gcc version 7.1.1 20170630 (GCC) ) #1 SMP PREEMPT Sun Aug 13 20:28:47 UTC 2017 google-chrome version: 60.0.3112.101 (Official Build) (64-bit)

here’s my test code:

import requests
from pycookiecheat import chrome_cookies


if __name__ == '__main__':
      url = 'https://www.google.com'
      cookies = chrome_cookies(url)

hers’s traceback:

➜  crawer git:(master) ✗ python pycookietest.py 
Traceback (most recent call last):
  File "pycookietest.py", line 7, in <module>
    cookies = chrome_cookies(url)
  File "/usr/lib/python3.6/site-packages/pycookiecheat/pycookiecheat.py", line 216, in chrome_cookies
    init_vector=config['init_vector'])
  File "/usr/lib/python3.6/site-packages/pycookiecheat/pycookiecheat.py", line 64, in chrome_decrypt
    return clean(decrypted)
  File "/usr/lib/python3.6/site-packages/pycookiecheat/pycookiecheat.py", line 41, in clean
    return decrypted[:-last].decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 0: invalid start byte

And I also research the issue https://github.com/n8henrie/pycookiecheat/issues/12 I was wondering if the value of my_pass is wrong, so I print every detail in decrypt process here’s return:

encrypted_value:  b'v11\n?r\xec\xcb\x8f\x8f\x1c\x08\x05A 8\xec\x81N~7\xc1O\xa0\xc0\xdd\xbb\xfb\xaa=\xfb\x90\xbd\x1f$'
unlocked_keyring:  []
my_pass:  peanuts
decrypted_value:  b's\t\xdd\xf6mp\x97\x12v\xcf\xd7\x9b\x1c\x83\xf5;\xdd\xa1\xf5\xf5\xe0!S\xb9\xa4\x85C\xbc\xb4\x8b\x93A'
clean_decrypted_value:  

unlocked_keyring was got from your code clean_decrypted_value is ues clean() function got. Some clean_decrypted_value is None, some are runs faild, and got the same log UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 0: invalid start byte.

Please help me figure this out. Thanks!

BTW, forgive my poor English…

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (15 by maintainers)

Most upvoted comments

Had the same issue, the next solution helped:

import secretstorage

bus = secretstorage.dbus_init()
collection = secretstorage.get_default_collection(bus)
for item in collection.get_all_items():
    if item.get_label() == 'Chrome Safe Storage':
        MY_PASS = item.get_secret()
        break
else:
    raise Exception('Chrome password not found!')

found here https://stackoverflow.com/a/44808566

I was experiencing the same issue. It turned out that the problem was that pycookiecheat was running in a virtualenv with no access to the system-level gi package. pycookiecheat fails silently if the package is not found.

Some solutions to this problem:

  1. Create the virtualenv with --system-site-packages
  2. Install PyGObject in the virtualenv: pip install PyGObject (requires some build dependencies)
  3. Symlinks the system sites-package into the virtualenv
  4. Use vext: pip install vext.gi

Yes, I left the default my_pass as far as I can recall. Will try to double check soon.