mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 07:01:22 -07:00
Fix grafana_dashboard py2/3 compatibility (#49194)
* Fix grafana_dashboard py2 compatibility * Convert URL output to a text/unicode string for json.loads
This commit is contained in:
parent
920be06670
commit
b079070688
1 changed files with 5 additions and 2 deletions
|
@ -140,6 +140,7 @@ import json
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.urls import fetch_url, url_argument_spec
|
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_native
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
@ -182,8 +183,10 @@ def get_grafana_version(module, grafana_url, headers):
|
||||||
r, info = fetch_url(module, '%s/api/frontend/settings' % grafana_url, headers=headers, method='GET')
|
r, info = fetch_url(module, '%s/api/frontend/settings' % grafana_url, headers=headers, method='GET')
|
||||||
if info['status'] == 200:
|
if info['status'] == 200:
|
||||||
try:
|
try:
|
||||||
settings = json.loads(r.read())
|
settings = json.loads(to_text(r.read()))
|
||||||
grafana_version = str.split(settings['buildInfo']['version'], '.')[0]
|
grafana_version = settings['buildInfo']['version'].split('.')[0]
|
||||||
|
except UnicodeError as e:
|
||||||
|
raise GrafanaAPIException('Unable to decode version string to Unicode')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise GrafanaAPIException(e)
|
raise GrafanaAPIException(e)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue