Skip to content

Commit

Permalink
Merge pull request #124 from DMTF/Query-Encoding
Browse files Browse the repository at this point in the history
Modified query parameter encoding to not percent-encode characters allowed in query strings per RFC3986
  • Loading branch information
mraineri committed May 12, 2022
2 parents 16af08c + b668996 commit 05659e3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/redfish/rest/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,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
Expand All @@ -811,12 +812,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))
Expand Down Expand Up @@ -857,7 +858,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()
Expand Down

0 comments on commit 05659e3

Please sign in to comment.