question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:25 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
ikhzcommented, Jan 17, 2019

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

1reaction
f3anarocommented, Aug 31, 2021

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
Read more comments on GitHub >

github_iconTop Results From Across the Web

error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
Python tries to convert a byte-array (a bytes which it assumes to be a utf-8-encoded string) to a unicode string ( str )....
Read more >
Error using grass v.clean: " 'utf-8' codec can't decode byte... "
Try to play around with encoding of your vector line layer (e.g. using ISO 8859-1, ISO 8859-15, Windows 1250). However, the UTF-8 should...
Read more >
UnicodeDecodeError utf-8 codec can t decode byte in position ...
While I importing the file it shows UnicodeDecodeError: "utf-8" codec can"t decode byte 0xa0 in position ... as pd a ...
Read more >
'utf8' codec can't decode byte 0xca in position 8: invalid ...
UnicodeDecodeError : 'utf8' codec can't decode byte 0xca in position 8: invalid continuation byte ; normal ; Invalid byte sequence in filepath is...
Read more >
Unicode & Character Encodings in Python: A Painless Guide
Unicode vs UTF-8; Encoding and Decoding in Python 3; Python 3: All-In on Unicode; One Byte, Two Bytes, Three Bytes, Four; What About...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found