diff --git a/pyghmi/ipmi/oem/lenovo/imm.py b/pyghmi/ipmi/oem/lenovo/imm.py index fa730eb0..4dd15b4b 100644 --- a/pyghmi/ipmi/oem/lenovo/imm.py +++ b/pyghmi/ipmi/oem/lenovo/imm.py @@ -1035,18 +1035,14 @@ class XCCClient(IMMClient): adata = json.dumps({'username': self.username, 'password': self.password }) - nonce = None - wc.request('POST', '/api/providers/get_nonce', '{}') - rsp = wc.getresponse() - tokbody = rsp.read() - if rsp.status == 200: - rsp = json.loads(tokbody) - nonce = rsp.get('nonce', None) headers = {'Connection': 'keep-alive', 'Referer': 'https://xcc/', 'Host': 'xcc', 'Content-Type': 'application/json'} - if nonce: + rsp, status = wc.grab_json_response_with_status( + '/api/providers/get_nonce', {}) + if status == 200: + nonce = rsp.get('nonce', None) headers['Content-Security-Policy'] = 'nonce={0}'.format(nonce) wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() diff --git a/pyghmi/redfish/oem/lenovo/xcc.py b/pyghmi/redfish/oem/lenovo/xcc.py index 54871962..8c6e9c10 100644 --- a/pyghmi/redfish/oem/lenovo/xcc.py +++ b/pyghmi/redfish/oem/lenovo/xcc.py @@ -628,6 +628,11 @@ class OEMHandler(generic.OEMHandler): 'Referer': referer, 'Host': 'xcc', 'Content-Type': 'application/json'} + rsp, status = wc.grab_json_response_with_status( + '/api/providers/get_nonce', {}) + if status == 200: + nonce = rsp.get('nonce', None) + headers['Content-Security-Policy'] = 'nonce={0}'.format(nonce) wc.request('POST', '/api/login', adata, headers) rsp = wc.getresponse() if rsp.status == 200: