From e1b72ab75c210a3a87a6ed08f2f3f6a23d4c0e2c Mon Sep 17 00:00:00 2001 From: archerwen Date: Tue, 10 Dec 2024 10:50:12 +0800 Subject: [PATCH 1/2] change the rest resp as json format Signed-off-by: archerwen --- src/redfish/rest/v1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/redfish/rest/v1.py b/src/redfish/rest/v1.py index 200f7ef..8c89937 100644 --- a/src/redfish/rest/v1.py +++ b/src/redfish/rest/v1.py @@ -951,11 +951,11 @@ def _rest_request(self, path, method='GET', args=None, body=None, try: LOGGER.debug('HTTP RESPONSE for %s:\nCode: %s\n\nHeaders:\n' \ - '%s\nBody Response of %s: %s\n'%\ + '%s\nBody Response of %s:\n%s\n'%\ (restresp.request.path, str(restresp._http_response.status_code)+ ' ' + \ restresp._http_response.reason, - headerstr, restresp.request.path, restresp.read)) + headerstr, restresp.request.path, json.dumps(json.loads(restresp.read), indent=4))) except: LOGGER.debug('HTTP RESPONSE:\nCode:%s', restresp) else: From 5c43a93262b973afca2c156a037f264f55f818b8 Mon Sep 17 00:00:00 2001 From: archerwen Date: Wed, 11 Dec 2024 10:36:41 +0800 Subject: [PATCH 2/2] determine and transfer the rest response as a json format dynamically Signed-off-by: archerwen --- src/redfish/rest/v1.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/redfish/rest/v1.py b/src/redfish/rest/v1.py index 8c89937..e000930 100644 --- a/src/redfish/rest/v1.py +++ b/src/redfish/rest/v1.py @@ -950,12 +950,16 @@ def _rest_request(self, path, method='GET', args=None, body=None, headerstr += '\t' + header[0] + ': ' + header[1] + '\n' try: + try: + restrespstr = json.dumps(json.loads(restresp.read), indent=4) + except: + restrespstr = restresp.read LOGGER.debug('HTTP RESPONSE for %s:\nCode: %s\n\nHeaders:\n' \ '%s\nBody Response of %s:\n%s\n'%\ (restresp.request.path, str(restresp._http_response.status_code)+ ' ' + \ restresp._http_response.reason, - headerstr, restresp.request.path, json.dumps(json.loads(restresp.read), indent=4))) + headerstr, restresp.request.path, restrespstr)) except: LOGGER.debug('HTTP RESPONSE:\nCode:%s', restresp) else: