2

所以最近我尝试使用 Exchangelib,但我目前无法解决这个问题。这是我的代码:

    from exchangelib import DELEGATE, Account, Credentials, IMPERSONATION
    from exchangelib.configuration import Configuration

    config = Configuration(
        server='https://XXX',
        credentials=Credentials(username='XXX\\XXX', password='XXX')
    )
    account = Account(
        primary_smtp_address='mail@mail.com',
        config=config,
        autodiscover=False,
        access_type=DELEGATE,
    )

    for item in account.inbox.all().order_by('-datetime_received')[:20]:
        print(item.subject, item.sender, item.datetime_received)

目前我收到以下错误:

    File "Project/Exchange/standardoutlook2.py", line 23, in <module>
        config = Configuration(server='https://XXX', credentials=credentials)
    File "Projectvenv36\lib\site-packages\exchangelib\configuration.py", line 46, in __init__
        version=version
    File "Projectvenv36\lib\site-packages\exchangelib\protocol.py", line 176, in __call__
        protocol = super(CachingProtocol, cls).__call__(*args, **kwargs)
    File "Projectvenv36\lib\site-packages\exchangelib\protocol.py", line 209, in __init__
        name=self.credentials.username)
    File "Projectvenv36\lib\site-packages\exchangelib\transport.py", line 149, in get_service_authtype
        timeout=BaseProtocol.TIMEOUT)
    File "Projectvenv36\lib\site-packages\requests\sessions.py", line 559, in post
        return self.request('POST', url, data=data, json=json, **kwargs)
    File "Projectvenv36\lib\site-packages\requests\sessions.py", line 512, in request
        resp = self.send(prep, **send_kwargs)
    File "Projectvenv36\lib\site-packages\requests\sessions.py", line 622, in send
        r = adapter.send(request, **kwargs)
    File "Projectvenv36\lib\site-packages\requests\adapters.py", line 412, in send
        self.cert_verify(conn, request.url, verify, cert)
    File "Project/Exchange/standardoutlook2.py", line 13, in cert_verify
        }[urlparse(url).hostname]
    KeyError: 'https'

我已将证书添加到 certifi 的证书中,因此当我在上面的代码之外向服务器发起任何请求时,它运行良好。

4

0 回答 0