0

I have a string of date time in utc like:

2020-12-24T23:30:00+00:00

I want this to be coverted to html encoding:

2020-12-24T23%3A30%3A00%2B00%3A00

Can it be done using urllib?

1 Answer 1

2

You can use urllib.parse.quote.

>>> from urllib.parse import quote
>>> quote("2020-12-24T23:30:00+00:00")
'2020-12-24T23%3A30%3A00%2B00%3A00'

You can also use quote_from_bytes which is similar quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding

>>> from urllib.parse import quote_from_bytes
>>> quote_from_bytes("2020-12-24T23:30:00+00:00".encode("utf-8"))
'2020-12-24T23%3A30%3A00%2B00%3A00'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.