This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2008-11-12.13:30:37
SpamBayes Score 8.4726315e-07
Marked as misclassified No
Message-id <1226496639.44.0.872023396099.issue4306@psf.upfronthosting.co.za>
In-reply-to
Content
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().
History
Date User Action Args
2008-11-12 13:30:39vstinnersetrecipients: + vstinner
2008-11-12 13:30:39vstinnersetmessageid: <1226496639.44.0.872023396099.issue4306@psf.upfronthosting.co.za>
2008-11-12 13:30:38vstinnerlinkissue4306 messages
2008-11-12 13:30:38vstinnercreate