mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Previous fix to this failed to account for open_url returning a filehandle (#20097)
* Previous fix to this failed to account for open_url returning a filehandle
Fixes the bugs introduced by c6fb355
* read() from HTTPError for python-3.6+
HTTPError is funny. It contains a filehandle to read the response from
and also makes it available via a read() method. On earlier versions of
python (2 and 3) the read() method was enough to make it work with
json.load(). The newer version of json.load() needs a more complete
file interface than this and has stopped working. Read the bytes,
transform to str and pass it in manually to fix it.
This commit is contained in:
parent
f340b8d14f
commit
1786c81a65
1 changed files with 4 additions and 4 deletions
|
@ -93,9 +93,9 @@ 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(to_text(resp, errors='surrogate_or_strict'))
|
data = json.loads(to_text(resp.read(), errors='surrogate_or_strict'))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
res = json.load(e)
|
res = json.loads(to_text(e.fp.read(), errors='surrogate_or_strict'))
|
||||||
raise AnsibleError(res['detail'])
|
raise AnsibleError(res['detail'])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -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(to_text(return_data, errors='surrogate_or_strict'))
|
data = json.loads(to_text(return_data.read(), 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(to_text(resp, errors='surrogate_or_strict'))
|
data = json.loads(to_text(resp.read(), errors='surrogate_or_strict'))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@g_connect
|
@g_connect
|
||||||
|
|
Loading…
Reference in a new issue