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
MIMEText __init__ does not support Charset instance #60528
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='https://github.com/berkerpeksag'closed_at=<Date2014-09-26.21:58:57.085>created_at=<Date2012-10-25.15:49:32.881>labels= ['type-feature', 'expert-email']
title='MIMEText __init__ does not support Charset instance'updated_at=<Date2014-09-26.21:58:57.084>user='https://bugs.python.org/claudep'
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?
I don't think you missed anything. It doesn't look like this has ever worked, but you'd certainly think it would. The documentation doesn't claim anything about it one way or another. That probably means we should treat it as an enhancement rather than a bug fix, but I'm open to argument on that.
claudep commented on Oct 25, 2012
claudepmannequin
MannequinAuthor
More actions
It's fine for me to consider it as an enhancement. The fix might be as simple as replacing **{'charset': _charset} by **{'charset': str(charset)} in MIMEText __init_.
Activity
claudep commentedon Oct 25, 2012
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?
bitdancer commentedon Oct 25, 2012
I don't think you missed anything. It doesn't look like this has ever worked, but you'd certainly think it would. The documentation doesn't claim anything about it one way or another. That probably means we should treat it as an enhancement rather than a bug fix, but I'm open to argument on that.
claudep commentedon Oct 25, 2012
It's fine for me to consider it as an enhancement. The fix might be as simple as replacing **{'charset': _charset} by **{'charset': str(charset)} in MIMEText __init_.
berkerpeksag commentedon Sep 26, 2014
Here's an updated patch.
bitdancer commentedon Sep 26, 2014
The updated patch looks good to me. Go ahead and commit it.
python-dev commentedon Sep 26, 2014
New changeset d43d4d4ebf2c by Berker Peksag in branch 'default':
Issue bpo-16324: _charset parameter of MIMEText now also accepts email.charset.Charset instances.
https://hg.python.org/cpython/rev/d43d4d4ebf2c
berkerpeksag commentedon Sep 26, 2014
Thanks for the patch, Claude and thanks for the review, David!