user1986059
user1986059

Reputation: 433

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

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.

Upvotes: 21

Views: 33106

Answers (2)

user1907906
user1907906

Reputation:

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 would need to be:

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

Upvotes: 32

user1986059
user1986059

Reputation: 433

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

Upvotes: 10

Related Questions