STINNER Victor <[EMAIL PROTECTED]> added the comment: The first email example (the one using a file in the library documentation) opens a text in binary mode and use the ASCII charset. It's quite strange because I expect an text to use only characters, something like: charset = 'ASCII' # Create a text/plain message with open(textfile, 'r', encoding=charset) as fp: msg = MIMEText(fp.read(), 'plain', charset)
... and the example doesn't work: Traceback (most recent call last): File "y.py", line 11, in <module> msg = MIMEText(fp.read()) File "/home/haypo/prog/py3k/Lib/email/mime/text.py", line 30, in __init__ self.set_payload(_text, _charset) File "/home/haypo/prog/py3k/Lib/email/message.py", line 234, in set_payload self.set_charset(charset) File "/home/haypo/prog/py3k/Lib/email/message.py", line 269, in set_charset cte(self) File "/home/haypo/prog/py3k/Lib/email/encoders.py", line 60, in encode_7or8bit orig.encode('ascii') AttributeError: 'bytes' object has no attribute 'encode' Solutions: - Message.set_payload() have to block type different than str => or would it be possible to use bytes as payload??? - Fix the example to use characters The new attached patch fixes the example and check type in Message.set_payload(). Added file: http://bugs.python.org/file11993/email_example.patch _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4306> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com