From 011c0d59cb7305da71afa69408127a1d837218dd Mon Sep 17 00:00:00 2001 From: Johann Queuniet Date: Tue, 27 Nov 2018 16:42:10 +0100 Subject: [PATCH] Convert URL output to a text/unicode string for json.loads --- lib/ansible/modules/monitoring/grafana_dashboard.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/monitoring/grafana_dashboard.py b/lib/ansible/modules/monitoring/grafana_dashboard.py index 67f99e8433..262fe22002 100644 --- a/lib/ansible/modules/monitoring/grafana_dashboard.py +++ b/lib/ansible/modules/monitoring/grafana_dashboard.py @@ -141,6 +141,7 @@ import string from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_text __metaclass__ = type @@ -183,8 +184,10 @@ def get_grafana_version(module, grafana_url, headers): r, info = fetch_url(module, '%s/api/frontend/settings' % grafana_url, headers=headers, method='GET') if info['status'] == 200: try: - settings = json.loads(r.read()) + settings = json.loads(to_text(r.read())) grafana_version = settings['buildInfo']['version'].split('.')[0] + except UnicodeError as e: + raise GrafanaAPIException('Unable to decode version string to Unicode') except Exception as e: raise GrafanaAPIException(e) else: