X-Received: by 10.66.172.76 with SMTP id ba12mr2113467pac.26.1361851224880; Mon, 25 Feb 2013 20:00:24 -0800 (PST) X-Received: by 10.50.186.202 with SMTP id fm10mr1411587igc.10.1361851224811; Mon, 25 Feb 2013 20:00:24 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!jn4no6771570pbb.1!news-out.google.com!ov8ni17067pbb.1!nntp.google.com!su1no7278763pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Mon, 25 Feb 2013 20:00:24 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.80.108.19; posting-account=hEeMqAoAAAAN2L2NtWcUUUG7LStm2lEM NNTP-Posting-Host: 69.80.108.19 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: stmplib MIMEText charset weirdness From: "Adam W." Injection-Date: Tue, 26 Feb 2013 04:00:24 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:39929 Can someone explain to me why I can't set the charset after the fact and st= ill have it work. For example: >>> text =3D MIMEText('=E2=9D=A4=C2=A5'.encode('utf-8'), 'html') >>> text.set_charset('utf-8') >>> text.as_string() Traceback (most recent call last): File "", line 1, in text.as_string() File "C:\Python32\lib\email\message.py", line 168, in as_string g.flatten(self, unixfrom=3Dunixfrom) File "C:\Python32\lib\email\generator.py", line 91, in flatten self._write(msg) File "C:\Python32\lib\email\generator.py", line 137, in _write self._dispatch(msg) File "C:\Python32\lib\email\generator.py", line 163, in _dispatch meth(msg) File "C:\Python32\lib\email\generator.py", line 192, in _handle_text raise TypeError('string payload expected: %s' % type(payload)) TypeError: string payload expected: As opposed to: >>> text =3D MIMEText('=E2=9D=A4=C2=A5'.encode('utf-8'), 'html', 'utf-8') >>> text.as_string() 'Content-Type: text/html; charset=3D"utf-8"\nMIME-Version: 1.0\nContent-Tra= nsfer-Encoding: base64\n\n4p2kwqU=3D\n' Side question: >>> text =3D MIMEText('=E2=9D=A4=C2=A5', 'html') >>> text.set_charset('utf-8') >>> text.as_string() 'MIME-Version: 1.0\nContent-Transfer-Encoding: 8bit\nContent-Type: text/htm= l; charset=3D"utf-8"\n\n=E2=9D=A4=C2=A5' Why is it now 8-bit encoding?