1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Convert all results from open_url() into text before deserializing the json. (#20069)

Fixes #20012
This commit is contained in:
Toshio Kuratomi 2017-01-10 08:35:08 -08:00 committed by GitHub
parent 1ee69c07cc
commit c6fb355b58

View file

@ -32,7 +32,7 @@ from ansible.compat.six.moves.urllib.error import HTTPError
from ansible.compat.six.moves.urllib.parse import quote as urlquote, urlencode from ansible.compat.six.moves.urllib.parse import quote as urlquote, urlencode
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.galaxy.token import GalaxyToken from ansible.galaxy.token import GalaxyToken
from ansible.module_utils._text import to_native from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.urls import open_url from ansible.module_utils.urls import open_url
try: try:
@ -93,7 +93,7 @@ class GalaxyAPI(object):
display.vvv(url) display.vvv(url)
resp = open_url(url, data=args, validate_certs=self._validate_certs, headers=headers, method=method, resp = open_url(url, data=args, validate_certs=self._validate_certs, headers=headers, method=method,
timeout=20) timeout=20)
data = json.load(resp) data = json.load(to_text(resp, errors='surrogate_or_strict'))
except HTTPError as e: except HTTPError as e:
res = json.load(e) res = json.load(e)
raise AnsibleError(res['detail']) raise AnsibleError(res['detail'])
@ -119,7 +119,7 @@ class GalaxyAPI(object):
raise AnsibleError("Failed to get data from the API server (%s): %s " % (url, to_native(e))) raise AnsibleError("Failed to get data from the API server (%s): %s " % (url, to_native(e)))
try: try:
data = json.load(return_data) data = json.load(to_text(return_data, errors='surrogate_or_strict'))
except Exception as e: except Exception as e:
raise AnsibleError("Could not process data from the API server (%s): %s " % (url, to_native(e))) raise AnsibleError("Could not process data from the API server (%s): %s " % (url, to_native(e)))
@ -136,7 +136,7 @@ class GalaxyAPI(object):
url = '%s/tokens/' % self.baseurl url = '%s/tokens/' % self.baseurl
args = urlencode({"github_token": github_token}) args = urlencode({"github_token": github_token})
resp = open_url(url, data=args, validate_certs=self._validate_certs, method="POST") resp = open_url(url, data=args, validate_certs=self._validate_certs, method="POST")
data = json.load(resp) data = json.load(to_text(resp, errors='surrogate_or_strict'))
return data return data
@g_connect @g_connect