New submission from Hendrik Spiegel:
When creating a MIMEBase object with message/rfc822 mimetype invoking
the objects __str__ method results in an exception.
Even if this behaviour should be intended the error message "TypeError:
Expected list, got <type 'str'>" is not helpful.
To reproduce the problem run the attached script after creating the file
'test.eml' in the script's directory.
mimetype = mimetypes.guess_type(filename)[0]
maintype, subtype = mimetype.split('/')
attachment = MIMEBase(maintype, subtype)
attachment.set_payload(file(filename).read( ))
print attachment
#python MimebaseError.py
[1]
message/rfc822
Traceback (most recent call last):
File "MimebaseError.py", line 19, in <module>
main()
File "MimebaseError.py", line 16, in main
print attachment
File "email/message.py", line 116, in __str__
File "email/message.py", line 131, in as_string
File "email/generator.py", line 84, in flatten
File "email/generator.py", line 109, in _write
File "email/generator.py", line 135, in _dispatch
File "email/generator.py", line 266, in _handle_message
File "email/message.py", line 185, in get_payload
TypeError: Expected list, got <type 'str'>
----------
components: Library (Lib)
files: MimebaseError.py
messages: 58216
nosy: hsp
severity: normal
status: open
title: Failure when calling __str__ for MIMEBase(message, rfc822) objects
type: crash
versions: Python 2.4, Python 2.5
Added file: http://bugs.python.org/file8879/MimebaseError.py
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1556>
__________________________________
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
import mimetypes
#filename = 'MimebaseError.py'
filename = 'test.eml'
def main():
mimetype = mimetypes.guess_type(filename)[0]
print mimetype
maintype, subtype = mimetype.split('/')
attachment = MIMEBase(maintype, subtype)
attachment.set_payload(file(filename).read( ))
#attachment.get_payload()
#attachment.get_payload(0)
print attachment
main()
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com