Getting AttributeError: sender while iterating to get specific values

Getting AttributeError: sender while iterating to get specific values

交换查询迭代时抛出“AttributeError: sender”。与其他值(message_id 等)相同。我此时唯一的选择是在其周围放置一个 try/catch 并且需要在循环下重构大量内容。但是,我认为查询在正常情况下不应该由于任何数据问题而崩溃。请让我知道可能出了什么问题。似乎是 'bad' 电子邮件对象导致的?

kwargs = {"is_read": False}
kwargs["datetime_received__gt"] = some_date_time

filtered_items = my_exchange._service_account.inbox.filter(**kwargs)
filtered_items.page_size = 20

print(filtered_items.count())

3     <-- 3 objects

for sender_obj, msg_id, msg_subj, msg_text, msg_size in filtered_items.values_list("sender", "message_id", "subject", "text_body", "size").iterator():
    print(sender_obj)
    count = count + 1
    print(count)


Mailbox(name='Some User1', email_address='someuser1@myemail.acme', routing_type='SMTP', mailbox_type='Mailbox')
1
Mailbox(name='Some User2', email_address='someuser2@myemail.acme', routing_type='SMTP', mailbox_type='OneOff')
2

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/exchangelib/queryset.py", line 273, in __iter__
    yield from self._format_items(items=self._query(), return_format=self.return_format)
  File "/usr/local/lib/python3.6/site-packages/exchangelib/queryset.py", line 352, in _item_yielder
    yield item_func(i)
  File "/usr/local/lib/python3.6/site-packages/exchangelib/queryset.py", line 380, in <lambda>
    item_func=lambda i: tuple(f.get_value(i) for f in self.only_fields),
  File "/usr/local/lib/python3.6/site-packages/exchangelib/queryset.py", line 380, in <genexpr>
    item_func=lambda i: tuple(f.get_value(i) for f in self.only_fields),
  File "/usr/local/lib/python3.6/site-packages/exchangelib/fields.py", line 189, in get_value
    return getattr(item, self.field.name)
AttributeError: sender

您似乎正在尝试获取不是消息的内容的 sender 字段。可能您的收件箱包含会议请求或其他一些 non-message object.

我不确定这是不是一个错误。您期望获取没有 sender 字段的内容的 sender 属性的结果是什么?

如果您只想在列表中添加消息 object,您可以尝试在 item_class='IPF.Note'.

上添加过滤器