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
Broken code example in email module documentation #67699
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2015-02-25.16:16:47.323>created_at=<Date2015-02-24.15:15:02.649>labels= ['type-feature', 'docs']
title='Broken code example in email module documentation'updated_at=<Date2015-02-25.16:16:47.322>user='https://github.com/bmispelon'
>>> # Import smtplib for the actual sending function
... import smtplib
>>>
>>> # Import the email modules we'll need
... from email.mime.text import MIMEText
>>>
>>> # Open a plain text file for reading. For this example, assume that
... # the text file contains only ASCII characters.
... fp =open(textfile, 'rb')
>>> # Create a text/plain message
... msg = MIMEText(fp.read())
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python3.4/email/mime/text.py", line 33, in __init__
_text.encode('us-ascii')
AttributeError: 'bytes' object has no attribute 'encode'
Looks like the example wasn't updated during the python3 transition.
As long as we are changing it, we might as well make it use the file as a context manager.
bmispelon commented on Feb 25, 2015
bmispelonmannequin
MannequinAuthor
More actions
I wasn't sure if that was going to be out of scope or not.
Here's an attached patch that fixes the remaining usages of open inside [Doc/includes](https://github.com/python/cpython/blob/main/Doc/includes) to always use a context manager.
Activity
bmispelon commentedon Feb 24, 2015
The first code example at https://docs.python.org/3.5/library/email-examples.html throws an
AttributeErrorbecauseMIMEText's constructor expects astrobject, not abytesone:bmispelon commentedon Feb 24, 2015
Patch attached.
berkerpeksag commentedon Feb 24, 2015
LGTM.
bitdancer commentedon Feb 25, 2015
Looks like the example wasn't updated during the python3 transition.
As long as we are changing it, we might as well make it use the file as a context manager.
bmispelon commentedon Feb 25, 2015
I wasn't sure if that was going to be out of scope or not.
Here's an attached patch that fixes the remaining usages of
openinside[Doc/includes](https://github.com/python/cpython/blob/main/Doc/includes)to always use a context manager.python-dev commentedon Feb 25, 2015
New changeset 89c6a6c2dd1f by Berker Peksag in branch '3.4':
Issue bpo-23511: Port email-simple.py to Python 3.
https://hg.python.org/cpython/rev/89c6a6c2dd1f
New changeset cb911e1fb3dc by Berker Peksag in branch 'default':
Issue bpo-23511: Port email-simple.py to Python 3.
https://hg.python.org/cpython/rev/cb911e1fb3dc
berkerpeksag commentedon Feb 25, 2015
Thanks for the patch, Baptiste.