Search code examples
pythonapifor-loopoutlookruntime-error

for loop argument of type 'NoneType' is not iterable


I have problems with my python for loop, because it runs into the following error after a few mails:

Exception has occurred: TypeError
argument of type 'NoneType' is not iterable

So far I have not been able to find a solution to my problem.

Here is the code I mentioned:

for message in testing.get_messages():
    if '<noticket>' in message.subject:
        message.mark_as_read()
        print(message)
    else:
        print ("Checking...")

I use O365 as a Python package.


Solution

  • Apparently, message.subject is None. If I were you, I'd adjust the code this way:

    if message.subject is not None and '<noticket>' in message.subject:
        ...