I have a text that is part of html. I would like to save it to a file.
This works fine in debug mode in Eclipse, but fails on runtime from shell. I am using a short example of html that fails.
xx = '<input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" />'
with codecs.open('myfile.htm'), 'wb', encoding="utf-8") as output:
output.write(data)
and I get:
Exception 'ascii' codec can't decode byte 0xe2 in position XXX: ordinal not in range(128)
where XXX is the position in the relevant file of the "strange" symbols, such as the EURO sign.
Why is this working from Eclipse and not from shell? How do I solve this?
I tried
HTMLParser.HTMLParser().unescape()
unquote()
unicode()
Nothing worked...
xxan actual variable in the code or just a fragment of the file you're giving as the example?charsetisContent-Typewhich for this page isContent-Type text/html; charset=utf-8