[New-bugs-announce] [issue5423] Exception raised when attempting to call set_charset on an email.mime.multipart once sub-parts have been attached

Chris Withers report at bugs.python.org
Thu Mar 5 14:01:13 CET 2009


New submission from Chris Withers <chris at simplistix.co.uk>:

Hi All,

I'm splitting this out from [Issue1823] as it's a separate issue.

Here's a minimal case to reproduce:

>>> from email.MIMEMultipart import MIMEMultipart
>>> from email.MIMEText import MIMEText
>>> msg = MIMEMultipart()
>>> msg.attach(MIMEText('foo','plain'))
>>> msg.set_charset('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\python24\lib\email\Message.py", line 260, in set_charset
    self._payload = charset.body_encode(self._payload)
  File "C:\python24\lib\email\Charset.py", line 366, in body_encode
    return email.base64MIME.body_encode(s)
  File "C:\python24\lib\email\base64MIME.py", line 136, in encode
    enc = b2a_base64(s[i:i + max_unencoded])
TypeError: b2a_base64() argument 1 must be string or read-only buffer, 
not list

NB: The exception raised can vary depending on the character set used:

>>> msg.set_charset('iso-8859-15')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\python24\lib\email\Message.py", line 260, in set_charset
    self._payload = charset.body_encode(self._payload)
  File "C:\python24\lib\email\Charset.py", line 368, in body_encode
    return email.quopriMIME.body_encode(s)
  File "C:\python24\lib\email\quopriMIME.py", line 180, in encode
    body = fix_eols(body)
  File "C:\python24\lib\email\Utils.py", line 62, in fix_eols
    s = re.sub(r'(?<!\r)\n', CRLF, s)
  File "C:\python24\lib\sre.py", line 142, in sub
    return _compile(pattern, 0).sub(repl, string, count)
TypeError: expected string or buffer

Chris

----------
messages: 83193
nosy: Sharebear, barry, christian.heimes, cjw296, loewis
severity: normal
status: open
title: Exception raised when attempting to call set_charset on an email.mime.multipart once sub-parts have been attached

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


More information about the New-bugs-announce mailing list