You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Failure when calling __str__ for MIMEBase(message, rfc822) objects #45897
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.
#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 mainprint 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_payloadTypeError: Expected list, got <type 'str'>
I don't really think the MIMEBase class is supposed to be used like
this, or at all: it behaves more like a Multipart message in that it
expects to carry a list of MIMEBase objects as a payload (not a string!)
though it doesn't define a boundary by default.
You can carry on using the MIMEBase class, but changing the line that says:
Activity
hsp commentedon Dec 5, 2007
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.
#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'>elachuni commentedon Jun 21, 2008
I don't really think the MIMEBase class is supposed to be used like
this, or at all: it behaves more like a Multipart message in that it
expects to carry a list of MIMEBase objects as a payload (not a string!)
though it doesn't define a boundary by default.
You can carry on using the MIMEBase class, but changing the line that says:
for:
I'd recommend you to use:
or if you want a multipart message:
facundobatista commentedon Jun 21, 2008
I agree with Anthony. If you have any further questions regarding how to
use this library feel free to ask them in python-list.