Skip to content

Commit

Permalink
fix(dashboard): specify utf-8 as encoding when opening files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rrey committed Oct 9, 2022
1 parent 083f0b7 commit defa8b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/191.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- grafana_dashboard, now opens json files with utf-8 encoding (#191)
4 changes: 2 additions & 2 deletions plugins/modules/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit defa8b9

Please sign in to comment.