This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cannot create multipart alternative message with us-ascii charset
Type: behavior Stage: resolved
Components: email Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Viktor.Szépe, barry, iritkatriel, r.david.murray
Priority: normal Keywords:

Created on 2014-05-23 22:59 by Viktor.Szépe, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg219009 - (view) Author: Viktor Szépe (Viktor.Szépe) Date: 2014-05-23 22:59
Python 2.7.6 (default, May 22 2014, 00:19:36)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from email.mime.multipart import MIMEMultipart
>>> new_msg = MIMEMultipart('alternative')
>>> new_msg.set_charset('us-ascii')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/python/lib/python2.7/email/message.py", line 268, in set_charset
    cte(self)
  File "/opt/python/lib/python2.7/email/encoders.py", line 73, in encode_7or8bit
    orig.encode('ascii')
AttributeError: 'list' object has no attribute 'encode'
>>>


I know it is not necessary.
How come that
new_msg.set_charset('us-ascii')
works?
msg219010 - (view) Author: Viktor Szépe (Viktor.Szépe) Date: 2014-05-23 23:01
Sorry!

How come that
new_msg.set_charset('utf-8')
works?
msg219607 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-02 17:20
I suspect this is either related to or is a duplicate of issue 1823.
msg382161 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-30 16:37
I'm not seeing the problem in 3.7(linux) and 3.10(windows). Is this a python 2-only issue?
msg386948 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-14 12:50
Works for me:

Python 3.10.0a5+ (heads/master:bf2e7e55d7, Feb 11 2021, 23:09:25) [MSC v.1928 64 bit (AMD64)] on win32
>>> from email.mime.multipart import MIMEMultipart
>>> new_msg = MIMEMultipart('alternative')
>>> new_msg.set_charset('us-ascii')
>>>
History
Date User Action Args
2022-04-11 14:58:03adminsetgithub: 65766
2021-02-14 12:50:28iritkatrielsetstatus: pending -> closed
resolution: out of date
messages: + msg386948

stage: resolved
2020-11-30 16:37:11iritkatrielsetstatus: open -> pending
nosy: + iritkatriel
messages: + msg382161

2018-07-11 07:35:51serhiy.storchakasettype: crash -> behavior
2014-06-02 17:20:22r.david.murraysetmessages: + msg219607
2014-05-23 23:01:47Viktor.Szépesetmessages: + msg219010
2014-05-23 22:59:43Viktor.Szépecreate