2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-30 21:07:40 +00:00

Force body to str for json

Some versions of python cannot take bytes
for the json payload.  Workaround by explicitly
decoding from utf8 in such a case.

Change-Id: Idb86003fcf6643e5c67e13202de41be6c35607a0
This commit is contained in:
Jarrod Johnson 2020-03-03 14:37:37 -05:00
parent 39a1fa0985
commit b48cdba5f3

View File

@ -228,6 +228,8 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
if rsp.getheader('Content-Encoding', None) == 'gzip':
body = gzip.GzipFile(fileobj=io.BytesIO(body)).read()
if rsp.status >= 200 and rsp.status < 300:
if body and not isinstance(body, str):
body = body.decode('utf8')
return json.loads(body) if body else {}, rsp.status
return body, rsp.status