How to decode a (doubly) 'url-encoded' string in python

折月煮酒 提交于 2019-12-03 11:00:42

问题


Tried decoding a url-encoded string in the following way

some_string = 'FireShot3%2B%25282%2529.png'
import urllib
res = urllib.unquote(some_string).decode()
res
u'FireShot3+%282%29.png'

Original string is FireShot3 (2).png. Any help would be appreciated.

Answer: urllib.unquote_plus(urllib.unquote_plus(some_string)) due to double encoding.


回答1:


Your input is encoded double. Using Python 3:

urllib.parse.unquote(urllib.parse.unquote(some_string))

Output:

'FireShot3+(2).png'

now you have the + left.

Edit:

Using Python 2.7 it of course is:

urllib.unquote(urllib.unquote('FireShot3%2B%25282%2529.png'))



回答2:


urllib.unquote_plus(urllib.unquote_plus(some_string)) FireShot3 (2).png



来源:https://stackoverflow.com/questions/28431359/how-to-decode-a-doubly-url-encoded-string-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!