[New-bugs-announce] [issue33972] AttributeError in email.message.iter_attachments()

Sven Krohlas report at bugs.python.org
Tue Jun 26 10:43:31 EDT 2018


New submission from Sven Krohlas <skrohlas at bfk.de>:

Hello everyone,

Today I stumbled over unexpected behaviour when parsing emails with Python 3.5.

mail is of type: <class 'email.message.EmailMessage'>


Traceback (most recent call last):
File "XXX", line YYY, in ZZZ
for attachment in mail.iter_attachments():
File "/usr/lib/python3.5/email/message.py", line 1025, in iter_attachments
parts = self.get_payload().copy()
AttributeError: 'str' object has no attribute 'copy'


/usr/lib/python3.5/email/message.py calls self.get_payload().copy() without distinguishing between different possible return types of get_payload().

get_payload() belongs to class MIMEPart(Message)

>From the (base) class Message:


"def get_payload(self, i=None, decode=False):
"""Return a reference to the payload.

The payload will either be a list object or a string."

So, it might return a string, which seems to be the case I'm hitting here.

The code in cpython trunk still looks identical apart from a few line offsets, so newer versions might be affected, too.

Am I doing something wrong or do we have a bug to squash here?

Thanks,
Sven

----------
components: email
messages: 320494
nosy: barry, r.david.murray, skrohlas
priority: normal
severity: normal
status: open
title: AttributeError in email.message.iter_attachments()
type: crash
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33972>
_______________________________________


More information about the New-bugs-announce mailing list