strodgers / epomaker-controller

29 stars 2 forks source link

(Windows 11) - UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 3826: character maps to <undefined> #46

Open Rustbeard86 opened 4 days ago

Rustbeard86 commented 4 days ago
Config file already exists at C:\Users\drewb\.epomaker-controller\config.json
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\drewb\AppData\Local\Programs\Python\Python312\Scripts\epomakercontroller.exe\__main__.py", line 4, in <module>
  File "C:\Users\drewb\AppData\Local\Programs\Python\Python312\Lib\site-packages\epomakercontroller\cli.py", line 19, in <module>
    CONFIGS = get_all_configs()
              ^^^^^^^^^^^^^^^^^
  File "C:\Users\drewb\AppData\Local\Programs\Python\Python312\Lib\site-packages\epomakercontroller\configs\configs.py", line 150, in get_all_configs
    ConfigType.CONF_KEYMAP : Config(ConfigType.CONF_KEYMAP, conf_keymap_path)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 6, in __init__
  File "C:\Users\drewb\AppData\Local\Programs\Python\Python312\Lib\site-packages\epomakercontroller\configs\configs.py", line 42, in __post_init__
    self.data = json.load(f)
                ^^^^^^^^^^^^
  File "C:\Users\drewb\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
                 ^^^^^^^^^
  File "C:\Users\drewb\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 3826: character maps to <undefined>
PS C:\Users\drewb> epomakercontroller.exe --help
Config file already exists at C:\Users\drewb\.epomaker-controller\config.json

I installed via unigetui.

To fix the issue I had to adjust "%USERPROFILE%\AppData\Local\Programs\Python\Python312\Lib\site-packages\epomakercontroller\configs\confgis.py

I modified line 41 as follows with open(self._find_config_path(self.filename, self.type), "r", encoding="utf-8") as f: Specifying the encoding type as utf-8.

I'm not much of a programmer, but dabble a bit, I'm unsure as to why this error occurs.

The config file written by the application was indeed UTF-8 encoded with Windows CR LF

Rustbeard86 commented 4 days ago

Everyt ime the application is run Config file already exists at C:\Users\drewb\.epomaker-controller\config.json is displayed. The config.json file is written to disk. Is this the intended behavior?

strodgers commented 3 days ago

@Rustbeard86 great find! I will update with the changes you suggested (https://github.com/strodgers/epomaker-controller/pull/47)

Apparently the default file encoding used by python is platform specific, so for Windows it's cp1252, but json.dump() defaults to using utf-8, so even though that particular file was written and then opened by the same program there's still a mismatch. I might do some experimenting with this, since it could also be a problem if a Windows user opens the config file to make changes and accidentally changes the encoding.

As for the print out, it is intended but isn't really needed anymore so I'll get rid of it.

Thanks very much!