Incrroect encoding when python read file
star-hengxing opened this issue · comments
Lines 22 to 31 in 1ecd457
If resource_exists
failed, script will use open
to read file, but local host encoding. So I got the error:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbf in position 2: illegal multibyte sequence
Here are some of my suggestions.
- It's not recommended to use
pkg_resources
.
https://setuptools.pypa.io/en/latest/pkg_resources.html
Use of pkg_resources is deprecated in favor of importlib.resources, importlib.metadata and their backports (importlib_resources, importlib_metadata). Some useful APIs are also provided by packaging (e.g. requirements and version parsing). Users should refrain from new usage of pkg_resources and should work to port to importlib-based solutions.
- Use
PYTHONWARNDEFAULTENCODING=1
to fix potential encoding errors.
Can you test again with the latest changes to master, would be good to know if the issues is actually fixed now.
It's not recommended to use pkg_resources.
Now it is, I think last I looked into it I needed 3.9 to make it actually work. Should update, but just a small refresher, this code technically still supports and works on Python 2.7. 3.9 is out now, so no reason to not actually use it if it's available.
It work fine, thanks.