Search code examples
python-3.xurllib2urlencode

how to encode url with urllib without replacing ":" into "%3A"?


I need to pass some string as a paramters for a REST api. I am using httplib2 to request the API and urllib to encode the parameters.

I have something like this with timestamp of format:

('%Y-%m-%dT%H:%M:%S')/2019-07-08T13:20:23

and i am doing it like this below:

values={'identifier' : identifier,
        'timestamp': timestamp,
        'signature-version': signature_version,
        'signature-method':signature_method,
         'signature': signature}

now on doing urlencode it removes ":" into "%3A".

data = urllib.parse.urlencode(values)

and it gives me back time as

timestamp=2019-07-08T13%3A20%3A23#

is there anything within the library that can ignore this? Thanks a lot!


Solution

  • If you are using urlencode, it would always turn ':' into '%3A' because that's the only way the url will parse it. It is the same as passing a space character as '%20'. '%3A' character won't hamper the function of your code.