how to get the subject of email?
luofeiyu
elearn2014 at gmail.com
Sat Aug 9 21:41:44 EDT 2014
I am in python3.4
typ, data = x.con.fetch(b'1', '(RFC822)') #get the first email
text = data[0][1]
message = email.message_from_string(text).get('subject')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python34\lib\email\__init__.py", line 40, in message_from_string
return Parser(*args, **kws).parsestr(s)
File "D:\Python34\lib\email\parser.py", line 70, in parsestr
return self.parse(StringIO(text), headersonly=headersonly)
TypeError: initial_value must be str or None, not bytes
message = email.message_from_string(str(text)).get('subject')
message # nothing displayed
More information about the Python-list
mailing list