djhtml icon indicating copy to clipboard operation
djhtml copied to clipboard

Djhtml fails to complete due to old default encoding on windows

Open jeriox opened this issue 1 year ago • 2 comments

When running djhtml on Windows 11 for my project, it fails with Error: 'charmap' codec can't decode byte 0x8f in position 622: character maps to <undefined>. According to various sources (e.g. https://stackoverflow.com/a/68650013) this is due to Windows using an outdated encoding (windows-1252) by default if no encoding is specified when opening the file. This encoding fails to read utf-8 characters. Adding encoding="utf-8" to the open() call in https://github.com/rtts/djhtml/blob/main/djhtml/main.py#L53 solves the problem for me.

jeriox avatar Jul 30 '24 12:07 jeriox

Yes, this is a known issue, which is why the README contains this paragraph:

Note that Windows still uses legacy code pages instead of UTF-8. It is highly advised to set the environment variable PYTHONUTF8 to 1 with the setx command:

C:\> setx /m PYTHONUTF8 1

If this can also be fixed by adding encoding="utf-8" to the open() call, that seems like a better solution and that paragraph can be removed. Can anyone concur? Or may some people still have valid reasons to not use UTF-8 in 2024?

JaapJoris avatar Jul 30 '24 14:07 JaapJoris

Yes, this is a known issue, which is why the README contains this paragraph:

My bad, I missed that part 😅 sorry for the inconvenience

jeriox avatar Jul 30 '24 18:07 jeriox