You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AttributeError: 'str' object has no attribute 'is_attachment' in email module when calling get_body #159304
Exception occurs in email module when malformed email stream is provided and get_body function is called. Working with Python 3.13 (debian-trixie). I found this PR: http://github.com/python/cpython/pull/27492/changes but it seems that the issue is still there.
Traceback
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[21], line 1
----> 1 msg = msg.get_body(("plain", "html"))
File /usr/lib/python3.13/email/message.py:1054, in MIMEPart.get_body(self, preferencelist)
1052 best_prio = len(preferencelist)
1053 body = None
-> 1054 for prio, part in self._find_body(self, preferencelist):
1055 if prio < best_prio:
1056 best_prio = prio
File /usr/lib/python3.13/email/message.py:1040, in MIMEPart._find_body(self, part, preferencelist)
1038 candidate = subparts[0] if subparts else None
1039 if candidate is not None:
-> 1040 yield from self._find_body(candidate, preferencelist)
File /usr/lib/python3.13/email/message.py:1040, in MIMEPart._find_body(self, part, preferencelist)
1038 candidate = subparts[0] if subparts else None
1039 if candidate is not None:
-> 1040 yield from self._find_body(candidate, preferencelist)
File /usr/lib/python3.13/email/message.py:1014, in MIMEPart._find_body(self, part, preferencelist)
1013 def _find_body(self, part, preferencelist):
-> 1014 if part.is_attachment():
1015 return
1016 maintype, subtype = part.get_content_type().split('/')
AttributeError: 'str' object has no attribute 'is_attachment'
Minimal reproduction
fromemail.messageimportEmailMessagefromemailimportmessage_from_stringmail_stream= (
"From: sender@example.com\r\n""To: receiver@example.com\r\n""Subject: Malformed\r\n""Content-Type: multipart/related; boundary=OUTER\r\n""\r\n""--OUTER\r\n""Content-Type: multipart/related\r\n""\r\n""raw body no boundary\r\n""--OUTER--"
)
msg=message_from_string(stream, _class=EmailMessage)
msg.get_body(("plain", "html"))
Activity
pythongh-159304: Fix AttributeError in email get_body() for nested ma…