From 8576fdadbffa1edfd2685e77b031e2dfef567d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REY?= Date: Mon, 22 Aug 2022 10:43:03 +0200 Subject: [PATCH] fix(dashboard): specify utf-8 as encoding when opening files No method of reproduction was found/provided for #191, as a prevention measure this patch specifies the encoding to use when opening a file to avoid the open function to auto determine the preferred encoding based on the locale. Closes: #191 --- changelogs/fragments/191.yml | 2 ++ plugins/modules/grafana_dashboard.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/191.yml diff --git a/changelogs/fragments/191.yml b/changelogs/fragments/191.yml new file mode 100644 index 00000000..67eb1303 --- /dev/null +++ b/changelogs/fragments/191.yml @@ -0,0 +1,2 @@ +bugfixes: + - grafana_dashboard, now opens json files with utf-8 encoding (#191) diff --git a/plugins/modules/grafana_dashboard.py b/plugins/modules/grafana_dashboard.py index 47971953..99801d49 100644 --- a/plugins/modules/grafana_dashboard.py +++ b/plugins/modules/grafana_dashboard.py @@ -305,7 +305,7 @@ def grafana_create_dashboard(module, data): payload = json.loads(r.read()) else: try: - with open(data['path'], 'r') as json_file: + with open(data['path'], 'r', encoding="utf-8") as json_file: payload = json.load(json_file) except Exception as e: raise GrafanaAPIException("Can't load json file %s" % to_native(e)) @@ -469,7 +469,7 @@ def grafana_export_dashboard(module, data): if dashboard_exists is True: try: - with open(data['path'], 'w') as f: + with open(data['path'], 'w', encoding="utf-8") as f: f.write(json.dumps(dashboard, indent=2)) except Exception as e: raise GrafanaExportException("Can't write json file : %s" % to_native(e))