damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)
https://damnever.github.io/pigar/
BSD 3-Clause "New" or "Revised" License
1.65k stars 90 forks source link

UnicodeDecodeError #168

Closed simonbuehler closed 1 year ago

simonbuehler commented 1 year ago

hi,

using it on windows i got this

 File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\pigar\parser.py", line 172, in _read_code
    return f.read()
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 90: character maps to <undefined>

https://github.com/damnever/pigar/blob/7b0395697f3af7dc0a6c5ee45ee554fd1801c8d3/pigar/parser.py#L171

i fixed it with with open(fpath, 'rb') as f:

damnever commented 1 year ago

I see.. this was introduced in a previous release. Would you like to submit a pull request for this fix?

damnever commented 1 year ago

pip install pigar==2.1.1 should fix this issue.