URL UTF-8 Decoding Python
Question: I am having some data in URL format and I want to decode it using Python. I
tried the (accepted) answer
[here](https://stackoverflow.com/questions/3563126/url-encoding-decoding-with-
python) but I am still not getting getting the correct decoding. My code is as
follows:

    
    
    import urllib2
    
    name = '%D0%BD%D0%BE%D1%82%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%82%D0%BE%D1%80-%D0%BE%D0%BB%D0%B8%D0%BC%D0%BF%D0%B8%D0%B9%D1%81%D0%BA%D0%B8%D1%85-%D0%B8'
    
    print urllib2.unquote(urllib2.quote(name.encode("utf8"))).decode("utf8")
    

This should print `нотификатор-олимпийских-и` but it prints
`%D0%BD%D0%BE%D1%82%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%82%D0%BE%D1%80-%D0%BE%D0%BB%D0%B8%D0%BC%D0%BF%D0%B8%D0%B9%D1%81%D0%BA%D0%B8%D1%85-%D0%B8`

so I tried unquoting it again

print
urllib2.unquote(urllib2.unquote(urllib2.quote(name.encode("utf8"))).decode("utf8"))

but it gives me `Ð½Ð¾ÑÐ¸ÑÐ¸ÐºÐ°ÑÐ¾Ñ-Ð¾Ð»Ð¸Ð¼Ð¿Ð¸Ð¹ÑÐºÐ¸Ñ-Ð¸`

I am not sure why this happens. Can anyone please explain where am I doing
wrong and how do I correct my mistake?


Answer: Too many quote/unquote operations: you get a UTF-8 string that is _already_
URL-encoded, why are you UTF-8 and URL encoding it again?

    
    
    unquoted = urllib.unquote(name)
    print unquoted.decode('utf-8')
    # нотификатор-олимпийских-и
    

