How fix unicode error in python when getting data from server -



How fix unicode error in python when getting data from server -

i have next text in server(in hi_how_are_you_guys.html file ). allow it

det är framförallt på de större lekplatser

now fetching info next code

result = requests.get("http://localhost/hi_how_are_you_guys.html")

i saving this

open("res.txt",'w').write(result.text.encode('utf-8'))

now res.txt like

det är framförallt på de större lekplatser

producing unicode error when trying

open("res.txt",'w').write(result.text)

how can save string in server ?

use open("res.txt",'w').write(result.text.encode(result.encoding)) or open("res.txt",'w').write(result.content).

python python-2.7 unicode

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -