'NoneType' 类型的 for 循环参数不可迭代
for loop argument of type 'NoneType' is not iterable
我的 python for 循环有问题,因为它在发送几封邮件后遇到以下错误:
Exception has occurred: TypeError
argument of type 'NoneType' is not iterable
到目前为止,我还没有找到解决问题的方法。
这是我提到的代码:
for message in testing.get_messages():
if '<noticket>' in message.subject:
message.mark_as_read()
print(message)
else:
print ("Checking...")
我使用 O365 作为 Python 包。
显然,message.subject
是 None
。如果我是你,我会这样调整代码:
if message.subject is not None and '<noticket>' in message.subject:
...
我打赌它可以帮助:
if testing.get_messages() is not None:
for message in testing.get_messages():
if '<noticket>' in message.subject:
message.mark_as_read()
print(message)
else:
print ("Checking...")
我的 python for 循环有问题,因为它在发送几封邮件后遇到以下错误:
Exception has occurred: TypeError
argument of type 'NoneType' is not iterable
到目前为止,我还没有找到解决问题的方法。
这是我提到的代码:
for message in testing.get_messages():
if '<noticket>' in message.subject:
message.mark_as_read()
print(message)
else:
print ("Checking...")
我使用 O365 作为 Python 包。
显然,message.subject
是 None
。如果我是你,我会这样调整代码:
if message.subject is not None and '<noticket>' in message.subject:
...
我打赌它可以帮助:
if testing.get_messages() is not None:
for message in testing.get_messages():
if '<noticket>' in message.subject:
message.mark_as_read()
print(message)
else:
print ("Checking...")