[docs] [issue23511] Broken code example in email module documentation

Baptiste Mispelon report at bugs.python.org
Tue Feb 24 16:15:02 CET 2015


New submission from Baptiste Mispelon:

The first code example at https://docs.python.org/3.5/library/email-examples.html throws an `AttributeError` because `MIMEText`'s constructor expects a `str` object, not a `bytes` one:

>>> # 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'

----------
assignee: docs at python
components: Documentation
messages: 236503
nosy: bmispelon, docs at python
priority: normal
severity: normal
status: open
title: Broken code example in email module documentation

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23511>
_______________________________________


More information about the docs mailing list