encoding problem

L

Luis Zarrabeitia

Hi, guys.
I'm trying to read an xml file and output some of the nodes. For that, I'm
doing a
print node.toprettyxml()

However, I get this exception:

===
out.write(tag.toxml())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position
190: ordinal not in range(128)
===

That happens if I "print" it, or send it to stdout, or send it to a file.

How can I fix it?
cat file works perfectly, and I'm using an utf8 terminal.

I'm particularly puzzled that it won't work even if I write to a file opened
in "b" mode. Worst thing is... I don't really need that character, just a
general idea of how the document looks like.
 
M

Mike Driscoll

Hi, guys.
I'm trying to read an xml file and output some of the nodes. For that, I'm
doing a
print node.toprettyxml()

However, I get this exception:

===
    out.write(tag.toxml())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position
190: ordinal not in range(128)
===

That happens if I "print" it, or send it to stdout, or send it to a file.

How can I fix it?
cat file works perfectly, and I'm using an utf8 terminal.

I'm particularly puzzled that it won't work even if I write to a file opened
in "b" mode. Worst thing is... I don't really need that character, just a
general idea of how the document looks like.


I recommend studying up on Python's Unicode methods and the codecs
module. This site actually talks about your specific issue though and
gives pointers:

http://evanjones.ca/python-utf8.html

HTH

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top