help with unicode email parse

N

neoedmund

i want to get the subject from email and construct a filename with the
subject.
but tried a lot, always got error like this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 4:
ordinal not in range(128)


msg = email.message_from_string( text )
title = decode_header( msg["Subject"] )
title= title[0][0]
#title=title.encode("utf8")
print title
fn = ""+path+"/"+stamp+"-"+title+".mail"


the variable "text" come from sth like this:
( header, msg, octets ) = a.retr( i )
text= list2txt( msg )
def list2txt( l ):
return reduce( lambda x, y:x+"\r\n"+y, l )

anyone can help me out? thanks.
 
D

Diez B. Roggisch

neoedmund said:
i want to get the subject from email and construct a filename with the
subject.
but tried a lot, always got error like this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 4:
ordinal not in range(128)


msg = email.message_from_string( text )
title = decode_header( msg["Subject"] )
title= title[0][0]
#title=title.encode("utf8")
print title
fn = ""+path+"/"+stamp+"-"+title+".mail"


the variable "text" come from sth like this:
( header, msg, octets ) = a.retr( i )
text= list2txt( msg )
def list2txt( l ):
return reduce( lambda x, y:x+"\r\n"+y, l )

anyone can help me out? thanks.

Where does the exception occur?

Diez
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top