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

Peter Hansen peter at engcorp.com
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!
> 
> ---- test.py ------------
> 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 test.py
> 
> Traceback (most recent call last):
>    g.flatten(msg.get_payload(0), unixfrom=False)
>  File "/usr/lib/python2.2/email/Message.py", 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.

-Peter




More information about the Python-list mailing list