Unescape Python Strings From HTTP

前端 未结 3 1826
梦谈多话
梦谈多话 2020-11-28 13:26

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 -> myemail@gmail.com
         


        
3条回答
  •  生来不讨喜
    2020-11-28 14:21

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

    >>> import urllib
    >>> urllib.unquote("myemail%40gmail.com")
    'myemail@gmail.com'
    

    There's also unquote_plus:

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

提交回复
热议问题