Message75785
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(). |
|
Date |
User |
Action |
Args |
2008-11-12 13:30:39 | vstinner | set | recipients:
+ vstinner |
2008-11-12 13:30:39 | vstinner | set | messageid: <1226496639.44.0.872023396099.issue4306@psf.upfronthosting.co.za> |
2008-11-12 13:30:38 | vstinner | link | issue4306 messages |
2008-11-12 13:30:38 | vstinner | create | |
|