2

我想在某个帐户的联系人列表中搜索并取回该联系人详细信息,但是由于异常,这里告诉的文件夹都没有工作。KeyError不知何故,我无法访问任何交换帐户文件夹。

是许可还是...?

代码 :

from exchangelib import Credentials, Account, Configuration
from exchangelib.protocol import NoVerifyHTTPAdapter, BaseProtocol

BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter

credentials = Credentials("YYY@XXX.com", 'PASSWORD')


account = Account(
    primary_smtp_address="Account@XXX.com",
    autodiscover=True, 
    credentials=credentials
)

print(account)  # work properly with printing my account
print(account.contacts)  # not work with KeyError Exception

错误 :

Warning (from warnings module):
  File "C:\Python\lib\site-packages\urllib3\connectionpool.py", line 857
    InsecureRequestWarning)
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
Traceback (most recent call last):
  File "C:\Python\lib\site-packages\cached_property.py", line 69, in __get__
    return obj_dict[name]
KeyError: 'contacts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dvp7\Desktop\ex.py", line 20, in <module>
    print(account.contacts)
  File "C:\Python\lib\site-packages\cached_property.py", line 73, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "C:\Python\lib\site-packages\exchangelib\account.py", line 169, in contacts
    return self.root.get_default_folder(Contacts)
  File "C:\Python\lib\site-packages\exchangelib\folders.py", line 965, in get_default_folder
    for f in self._folders_map.values():
  File "C:\Python\lib\site-packages\exchangelib\folders.py", line 928, in _folders_map
    for f in FolderCollection(account=self.account, folders=distinguished_folders).get_folders():
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 1053, in call
    shape=shape,
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 88, in _get_elements
    response = self._get_response_xml(payload=payload)
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 189, in _get_response_xml
    raise rme
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 171, in _get_response_xml
    res = self._get_soap_payload(soap_response=soap_response_payload)
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 227, in _get_soap_payload
    cls._raise_soap_errors(fault=fault)  # Will throw SOAPError or custom EWS error
  File "C:\Python\lib\site-packages\exchangelib\services.py", line 261, in _raise_soap_errors
    raise vars(errors)[code](msg)
exchangelib.errors.ErrorInternalServerError: An internal server error occurred. The operation failed.

构建版本:

Build=15.0.847.31, API=Exchange2013_SP1, Fullname=Microsoft Exchange Server 2013 SP1

这种方法是有效的:

account.root.walk() # output : <exchangelib.folders.FolderCollection object at 0x03ADCA90>

但是当我附加filter到它上面时发生了错误。

KeyError: 'folders'

只有root文件夹工作正常,里面什么都没有!

print(account.root.all())  # QuerySet(q=Q(), folders=[Root (root)])
4

2 回答 2

1

为了记录,这原来是一个行为不端的存档收件箱文件夹。https://github.com/ecederstrand/exchangelib/issues/431#issuecomment-409832287中提供的解决方法是告诉 exchangelib 忽略此文件夹:

from exchangelib.folders import ArchiveInbox
from exchangelib.version import EXCHANGE_2016

# Set to something newer than your current version
ArchiveInbox.supported_from = EXCHANGE_2016
于 2018-08-03T13:54:13.160 回答
0

对于那些通过搜索:exchangelib KeyError: 'inbox' 发现这个问题的人,我们的修复是升级到 1.11.4 以上。今天太平洋标准时间上午 9:15 之后是必要的

于 2019-07-22T23:35:44.237 回答