Skip to content

load_json_file encoding error on some files #2

@petergreen86

Description

@petergreen86

Some files fail with encoding errors:

Traceback (most recent call last):
  File "split_scan.py", line 50, in <module>
    scanData  = load_json_file(argv[1])
  File "split_scan.py", line 13, in load_json_file
    data = json.load(f)
  File "C:\Users\pgreen.SYNOPSYS\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\pgreen.SYNOPSYS\AppData\Local\Programs\Python\Python38\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 0x81 in position 899969521: character maps to <undefined>

This can be fixed by changing load_json_file to read as UTF-8

def load_json_file(filename):
    with open(filename, encoding='utf-8') as f:
        data = json.load(f)
    return data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions