2
0
mirror of https://opendev.org/x/pyghmi synced 2025-04-13 16:57:46 +00:00

Fix python3 incompatibilities

The python3 http support has some differences from python2.  Provide
compatibility for both python 2 and python 3.

Change-Id: Idb8d5815b0a540fc7ae4183bd033a2725d889930
This commit is contained in:
Jarrod Johnson 2018-10-30 14:42:01 -04:00
parent 2367c85f25
commit 84924a1f5c
2 changed files with 14 additions and 6 deletions

View File

@ -113,8 +113,8 @@ class IMMClient(object):
self.imm = ipmicmd.bmc
self.adp_referer = 'https://{0}/designs/imm/index-console.php'.format(
self.imm)
self.username = ipmicmd.ipmi_session.userid
self.password = ipmicmd.ipmi_session.password
self.username = ipmicmd.ipmi_session.userid.decode('utf-8')
self.password = ipmicmd.ipmi_session.password.decode('utf-8')
self._wc = None # The webclient shall be initiated on demand
self._energymanager = None
self.datacache = {}

View File

@ -104,7 +104,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
self.broken = False
self.thehost = host
self.theport = port
httplib.HTTPConnection.__init__(self, host, port, strict, **kwargs)
try:
httplib.HTTPConnection.__init__(self, host, port, strict=strict,
**kwargs)
except TypeError:
httplib.HTTPConnection.__init__(self, host, port, **kwargs)
self.cert_reqs = ssl.CERT_NONE # verification will be done ssh style..
if clone:
self._certverify = clone._certverify
@ -142,9 +146,13 @@ class SecureHTTPConnection(httplib.HTTPConnection, object):
def getresponse(self):
try:
rsp = super(SecureHTTPConnection, self).getresponse()
for hdr in rsp.msg.headers:
if hdr.startswith('Set-Cookie:'):
c = Cookie.BaseCookie(hdr[11:])
try:
hdrs = [x.split(':', 1) for x in rsp.msg.headers]
except AttributeError:
hdrs = rsp.msg.items()
for hdr in hdrs:
if hdr[0] == 'Set-Cookie':
c = Cookie.BaseCookie(hdr[1])
for k in c:
self.cookies[k] = c[k].value
except httplib.BadStatusLine: