From dec668cc217e8d4f79c2876d3fa843fbc6648c8a Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 5 Dec 2019 14:45:36 -0500 Subject: [PATCH] Convert BadStatusLine result If the BMC violates HTTP specification, just make it equivalent to a 500 error. Change-Id: I66f5cb5b39f03a6c738b1e52e596fd6bdc73c0bd --- pyghmi/util/webclient.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 27b8bb7a..d0122595 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -208,7 +208,14 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): if not method: method = 'GET' webclient.request(method, url, referer=referer, headers=headers) - rsp = webclient.getresponse() + try: + rsp = webclient.getresponse() + except httplib.BadStatusLine: + return 'Target Unavailable', 500 + except ssl.SSLError as e: + if 'timed out' in str(e): + return 'Target Unavailable', 500 + raise body = rsp.read() if rsp.getheader('Content-Encoding', None) == 'gzip': body = gzip.GzipFile(fileobj=io.BytesIO(body)).read()