From 51ec034e11926fd503761e9d56e1f08aa21b2ca2 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 15 Feb 2022 15:17:50 -0500 Subject: [PATCH] Try iso-8859-1 decode if utf8 fails Technically, the BMC is in error returning non-utf8 encoded content, however, of *course* some BMCs fail to do so. Fallback to iso-8859-1 which will probably have bad data in a value somewhere, but it won't break the entire parsing. Change-Id: Id7c3c507a0eeb4c31ca52cfadf6ac77deefa3869 --- pyghmi/util/webclient.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 3f632c4c..6d7f2201 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -253,8 +253,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): # gzip pass if rsp.status >= 200 and rsp.status < 300: - if body and not isinstance(body, str): - body = body.decode('utf8') + if body and not isinstance(body, type(u'')): + try: + body = body.decode('utf8') + except Exception: + body = body.decode('iso-8859-1') return json.loads(body) if body else {}, rsp.status return body, rsp.status