Python exchangelib支持多个字符串作为过滤器路径主题

问题描述

我正在尝试搜索包含多个主题的电子邮件,但是它在我的代码中仅支持单个主题字符串。如果搜索中缺少主题,我也希望将其打印出来。

if not testfolder.filter(
    datetime_received__gt=since,sender='anon@anon.dk',subject__icontains=['Backup - no index - Friday','backup - with no index']
    ).exists():
    print('Log mangler.. Sender Ticket til Kayako....')
else:
    print('email found')

ValueError:字段路径“主题”上的过滤器的值['Backup-no index-Friday','backup-no index']必须为单个值

解决方法

您可以为此使用Q()对象和布尔逻辑。参见https://ecederstrand.github.io/exchangelib/#searching

例如:

.filter(Q(subject__icontains='Backup - no index - Friday') | Q(subject__icontains='backup - with no index'))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...