I have a RESTful API I'm requesting from with query string parameters of date_start and date_end. The API documentation states the request should have the date time in a sort of ISO string, like this: 2019-06-15T00:22:55. Setting a date range would look like this:
https://path/to/api?start_date=2019-06-15T00:22:55&end_date=2019-08-05T19:55:33
Python requests, though, mangles it by wanting to escape the colons (:
), replacing them with %3A
, resulting in
https://path/to/api?start_date=2019-06-15T00%3A22%3A55&end_date=2019-08-05T19%3A55%3A33
Which, unfortunately, the API doesn't regard as a soluble parameter.
When I run the URL from Postman, that formatting doesn't get mangled. However, attempting to connect my app to the API using the typically amazing Requests library, it does the string escape conversion. I'm passing the parameter in a payload
-style key-value pair, advised by the requests docs, as follows:
info_id = 'abcXYZ1234'
url = 'path/to/sandbox'
start = '2019-06-15T00:00:00'
end = '2019-07-15T00:00:00'
payload = {'info_id': info_id, 'start_date': start, 'end_date': end}
r = requests.get(url, params=payload)
info = r.json()
How can I prevent requests from escaping colons?