pip-check-reqs icon indicating copy to clipboard operation
pip-check-reqs copied to clipboard

Encoding config support

Open iamgd67 opened this issue 4 years ago • 5 comments

add python script encoding config support, to handle some error like UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 797: illegal multibyte sequence

iamgd67 avatar Jan 22 '20 09:01 iamgd67

Thank you @iamgd67 . I know this is an old PR, but I would be happy to get a fix in for your issue.

Could you provide either/both of (ideally both) the following:

  • An issue which describes how to reproduce this problem.
  • A test case in this PR which fails without the fix.

adamtheturtle avatar Jun 18 '20 19:06 adamtheturtle

in my situation, it failes because when I process files with utf-8 encoding and contains chinese character on windows platform, looks like on windows open use gbk encoding default, and decode file failed.

iamgd67 avatar Jun 22 '20 09:06 iamgd67

It seems that ast.parse() can handle the encoding, so we can use open(filename, mode='rb') to solve this problem. The gbk encoding script file should add # coding: gbk line, see PEP263.

zhu avatar Jan 20 '21 01:01 zhu

Thanks for the work @zhu . Please ping me when tests are passing or I can help!

adamtheturtle avatar Jan 20 '21 11:01 adamtheturtle

Getting the same kind of error:

(venv) root@web:/var/www/html/python-tests/pronunciation-demo# pip-extra-reqs .
Traceback (most recent call last):
  File "/var/www/html/python-tests/pronunciation-demo/venv/bin/pip-extra-reqs", line 8, in <module>
    sys.exit(main())
  File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/find_extra_reqs.py", line 211, in main
    extras = find_extra_reqs(
  File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/find_extra_reqs.py", line 35, in find_extra_reqs
    used_modules = common.find_imported_modules(
  File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/common.py", line 151, in find_imported_modules
    content = file_obj.read()
  File "/usr/lib/python3.9/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 64: invalid start byte

Maybe more annoying is that it won't tell me on which file scan.

fabswt avatar Feb 11 '23 12:02 fabswt