From 6e1fae4c72cd6e10293413388ae0e12f2fac8a69 Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Sat, 16 Apr 2022 17:28:55 -0400 Subject: [PATCH 1/2] Modified query parameter encoding to not percent-encode characters allowed in query strings per RFC3986 Signed-off-by: Mike Raineri --- src/redfish/rest/v1.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/redfish/rest/v1.py b/src/redfish/rest/v1.py index 8c895d7..16c2e5a 100644 --- a/src/redfish/rest/v1.py +++ b/src/redfish/rest/v1.py @@ -794,6 +794,7 @@ def _rest_request(self, path, method='GET', args=None, body=None, LOGGER.error('Error occur while compressing body: %s', excp) raise + query_str = None if args: if method == 'GET': # Workaround for this: https://github.com/psf/requests/issues/993 @@ -805,12 +806,12 @@ def _rest_request(self, path, method='GET', args=None, body=None, none_list.append(query) else: args_copy[query] = args[query] - reqpath += '?' + urlencode(args_copy, quote_via=quote) + query_str = urlencode(args_copy, quote_via=quote, safe="/?:@!$'()*+,;\\=") for query in none_list: - if reqpath[-1] == '?': - reqpath += query + if len(query_str) == 0: + query_str += query else: - reqpath += '&' + query + query_str += '&' + query elif method == 'PUT' or method == 'POST' or method == 'PATCH': LOGGER.warning('For POST, PUT and PATCH methods, the provided "args" parameter "{}" is ignored.' .format(args)) @@ -851,7 +852,7 @@ def _rest_request(self, path, method='GET', args=None, body=None, verify = self.cafile resp = self._session.request(method.upper(), "{}{}".format(self.__base_url, reqpath), data=body, headers=headers, timeout=self._timeout, allow_redirects=allow_redirects, - verify=verify, proxies=self._proxies) + verify=verify, proxies=self._proxies, params=query_str) if sys.version_info < (3, 3): endtime = time.clock() From b6689965dd5df6b65a0a8e9ff7d854c5c6639235 Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Thu, 21 Apr 2022 09:24:56 -0400 Subject: [PATCH 2/2] Removed @ as a safe character since many servers don't handle it properly without percent-encoding Signed-off-by: Mike Raineri --- src/redfish/rest/v1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redfish/rest/v1.py b/src/redfish/rest/v1.py index 16c2e5a..2e517dd 100644 --- a/src/redfish/rest/v1.py +++ b/src/redfish/rest/v1.py @@ -806,7 +806,7 @@ def _rest_request(self, path, method='GET', args=None, body=None, none_list.append(query) else: args_copy[query] = args[query] - query_str = urlencode(args_copy, quote_via=quote, safe="/?:@!$'()*+,;\\=") + query_str = urlencode(args_copy, quote_via=quote, safe="/?:!$'()*+,;\\=") for query in none_list: if len(query_str) == 0: query_str += query