Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.

Home Page:https://glad.dav1d.de/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incrroect encoding when python read file

star-hengxing opened this issue · comments

if resource_exists(__name__, name):
logger.info('opening \'%s\' from packaged resource', name)
return resource_stream(__name__, name)
# fallback to filesystem
logger.info('opening \'%s\' from packaged path', name)
local_path = os.path.normpath(os.path.join(BASE_PATH, os.path.join(name)))
if not local_path.startswith(BASE_PATH):
raise ValueError
return open(local_path, *args, **kwargs)

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.