问题描述
我正在尝试搜索包含多个主题的电子邮件,但是它在我的代码中仅支持单个主题字符串。如果搜索中缺少主题,我也希望将其打印出来。
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'))