I want to mimic the decodeURIComponent and unescape that we have in JS in Python.
For example I get this string:
%25D7%2590%25D7%2591%25D7%2592
in JS I can do this:
decodeURIComponent(unescape('%25D7%2590%25D7%2591%25D7%2592'))
and get: אבג
I couldn't find any way to do it in Python, I'm using Tornado Web if it's relevant...
There's urllib.parse.unquote
in Python (or urlparse.unquote
in Python 2) to do that.
But I don't understand why the string you've posted is urlencoded twice. Because a single urlencoded string can be decoded just using decodeURIComponent
(without the unescape
).
Anyway, the Python version for this would be:
from urllib.parse import unquote # For Python 2 use: from urlparse import unquote
# decode twice because the string has been encoded twice.
unquote(unquote('%25D7%2590%25D7%2591%25D7%2592'))
For a single urlencoded string, you only need to use unquote
once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With