urlencode - Python encode url with special characters -
I want to encode url with special characters. In my case it is: Use UTF-8 explicitly then: And always look at the encoding in the status of your file. A non-UTF-8 string needs to be decoded first, then encoded: Å¡, ä, Ãμ, Ã, ø (this is not a limited list).
urllib2.quote (symbol) gives very strange results, which is not correct. How can these symbols be encoded?
urllib2.quote ("Grou Nlandsleiret, Oslo, Norway") a
% 27Gr% B8nlandsleiret% 2C% 20OSslo% 2C% 20 Norway% 27
urllib2.quote (u "Gromondelierre, Oslo, Norway" .xod ('utf-8'))
# You got a string. S = s.decode ('latin-1') # (Or what could be the encoding ?? |) # Now "s" is a unicode object S = s.encode ('utf-8') #UNT-8 string As encoded. # Now "s" is again a string S = urllib2.quote (s) # URL encoded # Now the "s" is encoded the way you need it.
Comments
Post a Comment