Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unescape Python Strings From HTTP

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?

like image 925
Ian Avatar asked Apr 23 '09 04:04

Ian


2 Answers

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.

like image 110
Paolo Bergantino Avatar answered Oct 07 '22 05:10

Paolo Bergantino


Yes, it appears that urllib.unquote() accomplishes that task. (I tested it against your example on codepad.)

like image 39
las3rjock Avatar answered Oct 07 '22 04:10

las3rjock