[New-bugs-announce] [issue17171] email.encoders.encode7or8bit does not work with binary data

R. David Murray report at bugs.python.org
Sat Feb 9 19:19:45 CET 2013

New submission from R. David Murray:

Reported by Serhiy in issue 16564:

>>> import io, email
>>> bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
>>> msg = email.mime.application.MIMEApplication(bytesdata, _encoder=encoders.encode_7or8bit)
>>> s = io.BytesIO()
>>> g = email.generator.BytesGenerator(s)
>>> g.flatten(msg)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 91, in flatten
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 137, in _write
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 163, in _dispatch
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 393, in _handle_text
    if _has_surrogates(msg._payload):
TypeError: can't use a string pattern on a bytes-like object

components: email
messages: 181748
nosy: barry, r.david.murray
priority: normal
severity: normal
stage: needs patch
status: open
title: email.encoders.encode7or8bit does not work with binary data
versions: Python 3.2, Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list