exchangelib KeyError:“联系人”或KeyError:“收件箱”或

时间:2018-06-23 11:41:20

标签: python-3.x exchangelib

我想在某个帐户的联系人列表中进行搜索,并获取该联系人的详细信息,但是由于input->post异常,告诉here的文件夹都不起作用。 不知何故我无法访问任何交换帐户文件夹。

是许可还是...?

代码:

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

2 个答案:

答案 0 :(得分:1)

出于记录目的,结果证明这是存档收件箱文件夹的异常行为。通过告诉Exchangelib忽略此文件夹,https://github.com/ecederstrand/exchangelib/issues/431#issuecomment-409832287中提供了解决方法:

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

# Set to something newer than your current version
ArchiveInbox.supported_from = EXCHANGE_2016

答案 1 :(得分:0)

对于那些通过搜索找到此问题的人:  exchangelib KeyError:“收件箱” 我们的解决方法是升级到1.11.4以上。太平洋标准时间今天上午9:15之后是必需的