JSONDecodeError and TypeError: can only concatenate str (not "bytes") to str error encountered when _do_web_request responses with status < 200 or status >= 300
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pyghmi |
Fix Committed
|
Undecided
|
Jarrod Johnson |
Bug Description
Pyghmi failed to provide actual exception when response status matches res[1] < 200 or res[1] >= 300 which leads consumer to unaware of actual problem
Details as in comments
def _do_web_
# Removed few lines
try:
res = wc.grab_
finally:
if 'If-Match' in wc.stdheaders: del wc.stdheaders[
if res[1] < 200 or res[1] >= 300: # response status matched this condition
try:
# removed few lines
except (ValueError, KeyError): # Catches the exception
When Added, raise exc.RedfishErro
I see below exception message as
Res: (b\'<?xml version="1.0" encoding=
Using python 3.9.18 and with invalid redfish endpoint like
To fix this probably we should check type before returning if condition not matched below
if rsp.status >= 200 and rsp.status < 300:
try:
body = body.decode('utf8')
except Exception:
body = body.decode( 'iso-8859- 1')
if body and not isinstance(body, type(u'')):
return json.loads(body) if body else {}, rsp.status
return body, rsp.status response_ with_status of pyghmi/ util/webclient. py L:273
in grab_json_