[issue16324] MIMEText __init__ does not support Charset instance

Claude Paroz report at bugs.python.org
Thu Oct 25 17:49:32 CEST 2012


New submission from Claude Paroz:

When initializing a MIMEText instance, it might be desirable to set the _charset parameter to a real Charset instance, not only a charset identifier (for example to pass a Charset with customized body_encoding). Unfortunately, this is failing:

  File ".../django/core/mail/message.py", line 128, in __init__
    MIMEText.__init__(self, text, subtype, charset)
  File "/usr/lib/python3.2/email/mime/text.py", line 29, in __init__
    **{'charset': _charset})
  File "/usr/lib/python3.2/email/mime/base.py", line 25, in __init__
    self.add_header('Content-Type', ctype, **_params)
  File "/usr/lib/python3.2/email/message.py", line 475, in add_header
    parts.append(_formatparam(k.replace('_', '-'), v))
  File "/usr/lib/python3.2/email/message.py", line 67, in _formatparam
    if value is not None and len(value) > 0:
TypeError: object of type 'Charset' has no len()

It is possible to later call set_charset, but the payload is already encoded (and 'Content-Transfer-Encoding' is set).
Did I miss anything?

----------
components: email
messages: 173764
nosy: barry, claudep, r.david.murray
priority: normal
severity: normal
status: open
title: MIMEText __init__ does not support Charset instance
type: behavior
versions: Python 3.2

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


More information about the Python-bugs-list mailing list