Gustaf Liljegren wrote:
f.write(header + self.all + footer)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 745-751: ordinal not in range(128)


The XML declaration should be enough to tell the encoding.

Sure, but that does not help at all. self.all is a Unicode string; information about its original encoding is not available anymore. If you want to write self.all to f, you need to encode it explicitly, e.g.

  f.write(header + self.all.encode("koi8-r") + footer)

Instead of koi8-r, you should use the enccoding of f, of course.

u = unicode(s, "utf-8")
xml.sax.parseString(u, MyParser())

This is not really supposed to work (yet). You need to pass byte strings to xml.sax.parseString, not Unicode strings.

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to