Ron Paulfan Ron Paulfan - 1 year ago 154
Python Question

Flanker: MimePart is not iterable

I'm a noob and using Flanker to parse emails.

I'm getting a Not Iterable error that I just can't seem to figure out. I've read tons of pages about lists, but I just can't get it to work. I'm hopeful I can get some help.

To run the following code, you will need to install Flanker, and save this file as 'email'.

I'm trying to read the 'attachmenttype' and do something depending on the response. Can't get it to work though. Here is the test code:

#Open Email
from flanker import mime
with open ("email", mode="rb") as myfile:

#Read Email
msg = mime.from_string(message_string)

#read attachment type
attachmenttype =[1]
print attachmenttype

#This errors for me: TypeError: argument of type 'MimePart' is not iterable
if attachmenttype:
if '(text/html)' in attachmenttype:
print "woohoo"

Here is the response I get:

Thanks in advance.

Answer Source

attachmenttype may be printed a string but it is not a string. However, since you can print it, you're halfway there. Just convert it to a string using str and compare that.

Fix your code like this. I couldn't test it but I don't see how it wouldn't work:

if attachmenttype:
    if '(text/html)' in str(attachmenttype):
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download