Problem with UnicodeError and xml.dom.minidom
gustafl at algonet.se
Mon Jun 11 17:08:45 EDT 2001
Paul Prescod <paulp at ActiveState.com> wrote:
>Sprinkle some calls to that around your code and even around the library
>code if you have to.
Thanks Paul, I'm closer to the solution now. I found a specific message in
the mailbox that gives the program trouble. Well, it isn't so specific --
it merely has some Swedish characters in the "From:" field...
The idea is to check if the "From:" field contains some of my friend's e-
mails, to sort them out. It looks like this:
for e in myFriend.getEmails(): # Friends often change e-mails...
if string.find(m.get('from'), e): # Here's the line that fails!
When I found this message, I could cut it out, and paste it at the
beginning of the mailbox file, and then provoke same error in Idle. I found
that the string returned from m.get('from') has some kind of hexadecimal
escaping for non-ASCII characters ('ä' is represented as '\xe4'), while the
'e' string containing the e-mail has a 'u' (for Unicode) in front. So that
explains why there is a problem when comparing them.
So, I wrapped a unicode() function around m.get('from'), but I still have
this same error: "UnicodeError: ASCII decoding error: ordinal not in
range(128)". Acctually, all I need to do to get this error is to write:
print unicode(m.get('from')) # Works fine without unicode() though
Hope this is enough info for someone to solve it. Otherwise, I'd gladly
share the complete code if you need. But it may be too much for a
More information about the Python-list