urlencode - Python encode url with special characters -


I want to encode url with special characters. In my case it is: Å¡, ä, Ãμ, Ã, ø (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

Use UTF-8 explicitly then:

  urllib2.quote (u "Gromondelierre, Oslo, Norway" .xod ('utf-8'))   

And always look at the encoding in the status of your file.


A non-UTF-8 string needs to be decoded first, then encoded:

  # 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

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -