From 8de92123f3dfbdc0e5c94716986718faf5e7bb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Wed, 27 Feb 2019 17:23:50 +0100 Subject: [PATCH] [2.7] cloudscale: fix compatibilty with older py3 versions (#52822) (#52915) * cloudscale: fix compatibilty with older py3 versions (#52822) * cloudscale: fix compatibilty with older py3 versions * add doc fragment (cherry picked from commit ee416fd01d2182747c70083996e0f546eb94ae7f) * cloudscale: improve error handling (#53054) (cherry picked from commit ca91ac2ca09821b64d2d93a3d6c56e975133a2c6) --- changelogs/fragments/52822-cloudscale_fix-py3.yaml | 2 ++ lib/ansible/module_utils/cloudscale.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/52822-cloudscale_fix-py3.yaml diff --git a/changelogs/fragments/52822-cloudscale_fix-py3.yaml b/changelogs/fragments/52822-cloudscale_fix-py3.yaml new file mode 100644 index 0000000000..6681ff144a --- /dev/null +++ b/changelogs/fragments/52822-cloudscale_fix-py3.yaml @@ -0,0 +1,2 @@ +bugfixes: +- cloudscale - Fix compatibilty with Python3 in version 3.5 and lower. diff --git a/lib/ansible/module_utils/cloudscale.py b/lib/ansible/module_utils/cloudscale.py index e9bbc5b7eb..825eb64dae 100644 --- a/lib/ansible/module_utils/cloudscale.py +++ b/lib/ansible/module_utils/cloudscale.py @@ -6,10 +6,9 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import json - from ansible.module_utils.basic import env_fallback from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_text API_URL = 'https://api.cloudscale.ch/v1/' @@ -35,7 +34,7 @@ class AnsibleCloudscaleBase(object): timeout=self._module.params['api_timeout']) if info['status'] == 200: - return json.loads(resp.read()) + return self._module.from_json(to_text(resp.read(), errors='surrogate_or_strict')) elif info['status'] == 404: return None else: @@ -56,7 +55,7 @@ class AnsibleCloudscaleBase(object): timeout=self._module.params['api_timeout']) if info['status'] in (200, 201): - return json.loads(resp.read()) + return self._module.from_json(to_text(resp.read(), errors='surrogate_or_strict')) elif info['status'] == 204: return None else: