Hello.
So, I am working with an API that does not use the “?” before the request params.
For example:
Instead of this:
https://api.rd.services/platform/contacts/?email=example@gmail.com
It works like this:
https://api.rd.services/platform/contacts/email:example@gmail.com
But if i use the request_params method, it always returns a ? before the email. How can I workaround this?
The ?
is added during the prepare_request
process.
This is made during the read_records
function where the method _create_prepared_request
builds the request.
def _create_prepared_request(
self, path: str, headers: Mapping = None, params: Mapping = None, json: Any = None, data: Any = None
) -> requests.PreparedRequest:
args = {"method": self.http_method, "url": urljoin(self.url_base, path), "headers": headers, "params": params}
if self.http_method.upper() in BODY_REQUEST_METHODS:
if json and data:
raise RequestBodyException(
"At the same time only one of the 'request_body_data' and 'request_body_json' functions can return data"
)
elif json:
args["json"] = json
elif data:
args["data"] = data
return self._session.prepare_request(requests.Request(**args))
I think you can overwrite the method to handle the ?
, but you need to check the Request
library how to do it.
Maybe if you join the url + params before calling the prepare_request
would works for you:
def prepare_url(self, url, params):
"""Prepares the given HTTP URL."""
#: Accept objects that have string representations.
#: We're unable to blindly call unicode/str functions
#: as this will include the bytestring indicator (b'')
#: on python 3.x.
#: https://github.com/psf/requests/pull/2238
if isinstance(url, bytes):
url = url.decode('utf8')
else:
url = str(url)
# Remove leading whitespaces from url
url = url.lstrip()
# Don't do any URL preparation for non-HTTP schemes like `mailto`,
# `data` etc to work around exceptions from `url_parse`, which
# handles RFC 3986 only.
if ':' in url and not url.lower().startswith('http'):
self.url = url
return
See lines 383-385