Skip to content

Issue with opening a file - UnicodeDecodeError #89

@Den2016

Description

@Den2016

When trying to open a file, an encoding error occurs.

Traceback (most recent call last):
File "C:\Bricklayers\bricklayers.py", line 139, in
process_gcode(
~~~~~~~~~~~~~^
input_file=args.input_file,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
layer_height=args.layerHeight,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
extrusion_multiplier=args.extrusionMultiplier,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Bricklayers\bricklayers.py", line 46, in process_gcode
lines = infile.readlines()
File "C:\Program Files\Python313\Lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 739: character maps to

Solution: explicitly specify the encoding when opening the file.

with open(input_file, 'r', encoding='utf-8') as infile:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions