From 0c20d79a8c2e01957aa9e50d5dded4d7f2239239 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 22 Oct 2019 09:05:33 -0400 Subject: [PATCH] Support newer TSM level Newer TSM requires JSON rather than form encoded auth. Try the newer method and fallback to form for compatibility. Change-Id: Ic0fd8fe949eb0bc328c57038e998d8c9570e7054 --- pyghmi/redfish/oem/lenovo/tsma.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyghmi/redfish/oem/lenovo/tsma.py b/pyghmi/redfish/oem/lenovo/tsma.py index 06e656da..d75cf460 100644 --- a/pyghmi/redfish/oem/lenovo/tsma.py +++ b/pyghmi/redfish/oem/lenovo/tsma.py @@ -128,7 +128,12 @@ class TsmHandler(generic.OEMHandler): 'password': self.password, } wc = webclient.SecureHTTPConnection(self.tsm, 443, verifycallback=self._certverify, timeout=180) - rsp, status = wc.grab_json_response_with_status('/api/session', urlencode(authdata)) + wc.set_header('Content-Type', 'application/json') + rsp, status = wc.grab_json_response_with_status('/api/session', authdata) + if status == 403: + wc.set_header('Content-Type', 'application/x-www-form-urlencoded') + rsp, status = wc.grab_json_response_with_status('/api/session', urlencode(authdata)) + if status < 200 or status >= 300: raise Exception('Error establishing web session') self.csrftok = rsp['CSRFToken']