21

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.

3
  • 1
    duplicates stackoverflow.com/questions/16566069/url-decode-utf-8-in-python 100% Commented Feb 10, 2015 at 12:12
  • 1
    @MarcusMüller: not quite. There is no UTF-8 encoded data there, the string has been URL encoded twice. Commented Feb 10, 2015 at 12:14
  • In Python 2, 3 or both? The library fn used will differ Commented Nov 14, 2017 at 18:28

2 Answers 2

31

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'))
Sign up to request clarification or add additional context in comments.

1 Comment

unqoute_plus handles the + character.
10

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.