Unescape Python Strings From HTTP

Ian picture Ian · Apr 23, 2009 · Viewed 19.2k times · Source

I've got a string from an HTTP header, but it's been escaped.. what function can I use to unescape it?

myemail%40gmail.com -> [email protected]

Would urllib.unquote() be the way to go?

Answer

Paolo Bergantino picture Paolo Bergantino · Apr 23, 2009

I am pretty sure that urllib's unquote is the common way of doing this.

>>> import urllib
>>> urllib.unquote("myemail%40gmail.com")
'[email protected]'

There's also unquote_plus:

Like unquote(), but also replaces plus signs by spaces, as required for unquoting HTML form values.