[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 ee416fd01d)

* cloudscale: improve error handling (#53054)


(cherry picked from commit ca91ac2ca0)
This commit is contained in:
René Moser 2019-02-27 17:23:50 +01:00 committed by Toshio Kuratomi
parent a79523acff
commit 8de92123f3
2 changed files with 5 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- cloudscale - Fix compatibilty with Python3 in version 3.5 and lower.

View file

@ -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: