From cf10f02a8de72e95a27ce4c6b225a262bc29dd72 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Sun, 18 Sep 2016 22:23:52 +0200 Subject: [PATCH] Fix utf8 errors Fix #681 --- gns3server/controller/project.py | 2 +- gns3server/controller/topology.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 8a4c98c8..48d9543d 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -648,7 +648,7 @@ class Project: topo = project_to_topology(self) path = self._topology_file() log.debug("Write %s", path) - with open(path + ".tmp", "w+") as f: + with open(path + ".tmp", "w+", encoding="utf-8") as f: json.dump(topo, f, indent=4, sort_keys=True) shutil.move(path + ".tmp", path) except OSError as e: diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index 9cc7a639..dfe537c0 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -89,7 +89,7 @@ def load_topology(path): """ log.debug("Read topology %s", path) try: - with open(path) as f: + with open(path, encoding="utf-8") as f: topo = json.load(f) except (OSError, UnicodeEncodeError, json.JSONDecodeError) as e: raise aiohttp.web.HTTPConflict(text="Could not load topology {}: {}".format(path, str(e))) @@ -98,7 +98,7 @@ def load_topology(path): # first we backup the file shutil.copy(path, path + ".backup") topo = _convert_1_3_later(topo, path) - with open(path, "w+") as f: + with open(path, "w+", encoding="utf-8") as f: json.dump(topo, f) elif topo["revision"] > GNS3_FILE_FORMAT_REVISION: raise aiohttp.web.HTTPConflict(text="This project is designed for a more recent version of GNS3 please update GNS3 to version {} or later".format(topo["version"]))