URL Decode with Python 3

PythonHtmlPython 3.x

Python Problem Overview


Is there a way to URL decode a string in Python 3

to take something like this

id%253D184ff84d27c3613d%26quality%3Dmedium

and decode it twice to get

id=184ff84d27c3613d&quality=medium

Python Solutions


Solution 1 - Python

Just use urllib.parse.unquote():

>>> import urllib.parse
>>> urllib.parse.unquote('id%253D184ff84d27c3613d%26quality%3Dmedium')
'id%3D184ff84d27c3613d&quality=medium'
>>> urllib.parse.unquote('id%3D184ff84d27c3613d&quality=medium')
id=184ff84d27c3613d&quality=medium

Solution 2 - Python

Try this:

from urllib.parse import unquote
s = 'id%253D184ff84d27c3613d%26quality%3Dmedium'
unquote(unquote(s))

It will return:

> 'id=184ff84d27c3613d&quality=medium'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVladikiView Question on Stackoverflow
Solution 1 - PythonBlenderView Answer on Stackoverflow
Solution 2 - PythonÓscar LópezView Answer on Stackoverflow