I am using python's urllib.parse.urlencode to encode a request body to make a 'get' request for a url. I am running into trouble when encoding a UTC datetime string.
The endpoints expects the date to look like:
begin=2004-01-01T00:00:00&end=2019-04-21T00:00:00
but after using urlencode, the date payload looks like:
begin=2020-02-04T17%3A00%3A00&end=2020-02-04T20%3A00%3A00
The format of the first half of the UTC datetime looks okay, (YYYY-MM-DDT), but second half is screwed up. It SHOULD look like T00:00:00
but does not.
I am passing a dictionary of parameters into the urlencode function:
params = {
'begin':'2020-02-04T17:00:00',
'end':'2020-02-04T20:00:00',
}
return urlencode(params, doseq=True)
How can I encode the date in the correct format? Please let me know if there is anything else I can provide to help you all. Thank you.
%3A
is :
when urlencoded.
Hence begin=2020-02-04T17:00:00&end=2020-02-04T20:00:00
when encoded will be begin=2020-02-04T17%3A00%3A00&end=2020-02-04T20%3A00%3A00
, as stated in your question.
The format is correct and there is nothing wrong with your code.