Url decode UTF-8 in Python

I have spent plenty of time as far as I am newbie in Python.
How could I ever decode such a URL:


to this one in python 2.7: example.com?title==правовая+защита

url=urllib.unquote(url.encode("utf8")) is returning something very ugly.

Still no solution, any help is appreciated.

The data is UTF-8 encoded bytes escaped with URL quoting, so you want to decode :

    url = urllib.unquote(url).decode('utf8')


    >>> import urllib 
    >>> url='example.com?title=%D0%BF%D1%80%D0%B0%D0%B2%D0%BE%D0%B2%D0%B0%D1%8F+%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%B0'
    >>> urllib.unquote(url).decode('utf8') 
    >>> print urllib.unquote(url).decode('utf8')

The Python 3 equivalent is urllib.parse.unquote(), which by default handles decoding for you:

    from urllib.parse import unquote

    url = unquote(url)

From: stackoverflow.com/q/16566069

Back to homepage or read more recommendations: