dflook / python-minifier

Transform Python source code into its most compact representation
MIT License
553 stars 40 forks source link

UnicodeEncodeError? #68

Open FrancHR opened 1 year ago

FrancHR commented 1 year ago

Last few days i have UnicodeEncodeError. Never had this before until now. There is no matter which code i have in py files. I also tried files which has successfully minified in the past, but now they have UnicodeEncodeError. I had version 2.6.0, and today i have updated to 2.8.0 and i have the same error.

Python version 3.9 on Windows 11.

C:\Users\Zet>pyminify C:\Users\Zet\Desktop\work\wrapper.py --in-place

C:\Users\Zet\Desktop\work\wrapper.py
Traceback (most recent call last):
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python39\Scripts\pyminify.exe\__main__.py", line 7, in <module>
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python39\lib\site-packages\python_minifier\__main__.py", line 64, in main
    f.write(minified)
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1988-1994: character maps to <undefined>

Also, tried in python 3.11:

C:\Users\Zet>pyminify C:\Users\Zet\Desktop\work\main.py --in-place

C:\Users\Zet\Desktop\work\main.py
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python311\Scripts\pyminify.exe\__main__.py", line 7, in <module>
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python311\Lib\site-packages\python_minifier\__main__.py", line 64, in main
    f.write(minified)
  File "C:\Users\Zet\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 28221-28227: character maps to <undefined>

On Ubuntu 20.04 and pyminfy v.2.8.0, with the same files everything is ok.

dflook commented 1 year ago

This sounds related to #57