我正在使用 IMAP 客户端。在我返回一个 imapclient 对象后,我将它与电子邮件的id和我希望电子邮件标记的标签字符串一起传递给下面的函数。这通常有效,但在少数情况下我会收到此错误。
添加标签时调用的函数
def label_gmail_message(client, msgid, label):
"""Function to label gmail messages after parsing
Args:
client (obj): imap client object to mail server
msgid (str): id of message to label
label (str): label string to be used
"""
try:
client.add_gmail_labels(msgid, label)
except KeyError:
log.exception(f"KeyError when labelling message : {msgid} with label {label}")
抛出错误
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/analisa-0.1.0-py3.7.egg/email_parser/imap_client.py", line 359, in label_gmail_message
client.add_gmail_labels(msgid, label)
File "/usr/local/lib/python3.7/site-packages/imapclient/imapclient.py", line 1034, in add_gmail_labels
silent=silent)
File "/usr/local/lib/python3.7/site-packages/imapclient/imapclient.py", line 1370, in _gm_label_store
b'X-GM-LABELS', silent=silent)
File "/usr/local/lib/python3.7/site-packages/imapclient/imapclient.py", line 1392, in _store
fetch_key)
File "/usr/local/lib/python3.7/site-packages/imapclient/imapclient.py", line 1396, in _filter_fetch_dict
for msgid, data in iteritems(fetch_dict))
File "/usr/local/lib/python3.7/site-packages/imapclient/imapclient.py", line 1396, in <genexpr>
for msgid, data in iteritems(fetch_dict))
KeyError: b'X-GM-LABELS'