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

Peter Hansen peter at engcorp.com
Mon Apr 21 14:44:11 EDT 2003


Magnus Therning wrote:
> 
> Peter Hansen <peter at engcorp.com> wrote:
> > 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.
> 
> But no index is given, so that would indicate a bug, right?

Actually, if you look at the g.flatten() line in the traceback above,
you'll see that g.flatten() _is_ providing an index value of 0.  I
think that means somebody is not properly handling the documented 
special case where the TypeError is thrown.

-Peter




More information about the Python-list mailing list