2
0
mirror of https://opendev.org/x/pyghmi synced 2026-04-01 07:43:39 +00:00

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
This commit is contained in:
Jarrod Johnson
2022-02-15 15:17:50 -05:00
parent b5806c3c0a
commit 51ec034e11

View File

@@ -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