default character encoding in some machines with Win OS causes crash!
orsnaro opened this issue · comments
PR#58
The bug is actually easy to fix but causes the whole code to collapse.
Details
file i/o `open()` function have `encoding` argument that by default is set to the machine's default character encoding.-
Most Linux machines uses
utf-8
as default encoding which is ok with most languages characters, emojis and symbols. -
In Windows machines, a big portion of them uses
cp1252
as default encoding which is very limited:
open() docs: "if encoding is not specified the encoding used is platform dependent" see
-
Reproducing the bug
(as you see even if user didn't send any invalid characters, GPT sending one invalid character is enough to cause the bug) -
Fix
simply assigningopen( , encoding= "utf-8")
for all systems or detecting the system encoding first using:
import locale
sys_char_encoding = locale.getpreferredencoding()
#rest of the code
Thank you @orsnaro for catching this bug affecting Windows machines, I merged your fix...