Chris Withers ha scritto: > Hi All, > > The following piece of code is giving me issues: > > from email.Charset import Charset,QP > from email.MIMEText import MIMEText > charset = Charset('utf-8') > charset.body_encoding = QP > msg = MIMEText( > u'Some text with chars that need encoding: \xa3', > 'plain', > ) > msg.set_charset(charset) > print msg.as_string() > > Under Python 2.4.2, this produces the following output, as I'd expect: >
> [...] > However, under Python 2.4.3, I now get: > Try with: msg = MIMEText( u'Some text with chars that need encoding: \xa3', _charset='utf-8', ) and you will obtain the error: Traceback (most recent call last): File "<pyshell#4>", line 3, in -toplevel- _charset='utf-8', File "C:\Python2.4\lib\email\MIMEText.py", line 28, in __init__ self.set_payload(_text, _charset) File "C:\Python2.4\lib\email\Message.py", line 218, in set_payload self.set_charset(charset) File "C:\Python2.4\lib\email\Message.py", line 260, in set_charset self._payload = charset.body_encode(self._payload) File "C:\Python2.4\lib\email\Charset.py", line 366, in body_encode return email.base64MIME.body_encode(s) File "C:\Python2.4\lib\email\base64MIME.py", line 136, in encode enc = b2a_base64(s[i:i + max_unencoded]) UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 41: ordinal not in range(128) Regards Manlio Perillo -- http://mail.python.org/mailman/listinfo/python-list