From 41ff7b916bb1f38fec5edb62ce89b371038c41a2 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 19 Sep 2018 18:03:02 +1000 Subject: [PATCH] tools/utils: Fix issue with loading json files as ascii on python3 linux --- tools/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/utils.py b/tools/utils.py index 93e70430a0..730d1a1cec 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -30,6 +30,7 @@ import json from collections import OrderedDict import logging from intelhex import IntelHex +import io try: unicode @@ -367,9 +368,9 @@ def json_file_to_dict(fname): fname - the name of the file to parse """ try: - with open(fname, "r") as file_obj: - return json.loads(file_obj.read().encode('ascii', 'ignore'), - object_pairs_hook=OrderedDict) + with io.open(fname, encoding='ascii', + errors='ignore') as file_obj: + return json.load(file_obj, object_pairs_hook=OrderedDict) except (ValueError, IOError): sys.stderr.write("Error parsing '%s':\n" % fname) raise