Thrown UnicodeEncodeError in non-English language windows environment
Opened this issue · 1 comments
huruka commented
When bean file contains special characters that are beyond the scope of ASCII,running script thrown error as below:
>bean-black xxx.bean
Traceback (most recent call last):
File "C:\Users\python\current\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\python\current\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\python\current\Scripts\bean-black.exe\__main__.py", line 7, in <module>
File "C:\Users\python\current\lib\site-packages\click\core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "C:\Users\python\current\lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\python\current\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\python\current\lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\python\current\lib\site-packages\beancount_black\main.py", line 49, in main
formatter.format(tree, output_file)
File "C:\Users\python\current\lib\site-packages\beancount_black\formatter.py", line 576, in format
output_file.write("\n\n".join(sections))
File "C:\Users\python\current\lib\tempfile.py", line 483, in func_wrapper
return func(*args, **kwargs)
UnicodeEncodeError: 'gbk' codec can't encode character '\xa5' in position 211620: illegal multibyte sequence
But the file is saved in utf-8 encoding.
Then I try to write simple script that use the open function to write, it can be saved normally.
fangpenlin commented
Can you provide a sample file for reproducing this issue?