g200kg / kicad-gerberzipper

KiCad Plot&Zip script plugin
MIT License
56 stars 21 forks source link

Fix UnicodeDecodeError on macOS #15

Closed odaki closed 2 years ago

odaki commented 2 years ago

Hello g200kg.

Thanks for your useful plugin. I am requesting a pull request because I needed a slight modification to use it on macOS.

For macOS, an error occurs at startup.

スクリーンショット 2022-03-26 14 35 42
Traceback (most recent call last):

File "/Users/odaki/Documents/KiCad/6.0/3rdparty/plugins/com_github_g200kg_kicad-gerberzipper/gerber_zipper_action.py", line 209, in __init__
self.json_data.append(json.load(open(fname)))

File "/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.8/json/__init__.py", line 293, in load
return loads(fp.read(),

File "/Applications/KiCad/KiCad.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.8/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 1524: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/Users/odaki/Documents/KiCad/6.0/3rdparty/plugins/com_github_g200kg_kicad-gerberzipper/gerber_zipper_action.py", line 644, in Run
dialog = Dialog(None)

File "/Users/odaki/Documents/KiCad/6.0/3rdparty/plugins/com_github_g200kg_kicad-gerberzipper/gerber_zipper_action.py", line 211, in __init__
alert('JSON error \n\n File : %s\n%s' % (os.path.basename(fname), 

To suppress decoding errors, I try to use codecs.open() instead of open. After the change, the plugin is running without problems. Gerber file output is also fine.

If this modification method is acceptable, could you please merge it? If you have a better fix, please apply it.

Thank you in advance for your consideration.

g200kg commented 2 years ago

Thank you!!!