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 Aug 22, 2022
1 parent 75b9200 commit ea77d1a
Showing 1 changed file with 2 additions and 2 deletions.
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 ea77d1a

Please sign in to comment.