printing email parts of type message/external-body??

Peter Hansen peter at
Sun Apr 20 18:50:58 CEST 2003

Magnus Therning wrote:
> I am having problems with the following piece of code, would appreciate
> any insight that can be offered!
> ---- ------------
> from email.Message import Message
> meb_message = Message()
> meb_message.add_header('Content-Type', 'message/external-body',
>     access_type='local-file')
> meb_message.set_payload('name="test"\n')
> print meb_message
> -------------------------
> magnus at die:[test].$ python
> Traceback (most recent call last):
>    g.flatten(msg.get_payload(0), unixfrom=False)
>  File "/usr/lib/python2.2/email/", line 179, in get_payload
>    raise TypeError, i
> TypeError: 0

Almost looks like a bug.  According to email.Message's documentation,
a TypeError will be raised by get_payload() if an index parameter is
provided but the payload is a string, as in this case.

I would think email.Message.as_string() should be catching that case
and handling it differently.


More information about the Python-list mailing list