Skip to content Skip to sidebar Skip to footer

Check If A String Is Encoded/quoted In Python

I'm using a Python handler to respond to an HTTP API. I'm reading some url params into the handler. There are some params which needs mandatory encoded strings. How can I check if

Solution 1:

You can compare the string with its unquoted version:

>>> import urlparse
>>> s1 = 'handler?u=https%3A%2F%2Fstackoverflow.com'
>>> s2 = 'handler?u=https://stackoverflow.com'
>>> urlparse.unquote(s1) == s1
False
>>> urlparse.unquote(s2) == s2
True

Post a Comment for "Check If A String Is Encoded/quoted In Python"