From b48cdba5f3705d15167a1cf7156d1d5f9755bcc1 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 3 Mar 2020 14:37:37 -0500 Subject: [PATCH] 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 --- pyghmi/util/webclient.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index ea910f85..5230d111 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -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