很抱歉我的英语不太好:在windows域中,我尝试使用pypi站点上给出的示例连接到我们的exchangeserver (2010/SP3):
from exchangelib import DELEGATE, NTLM, Account, Credentials, Configuration
import os, logging
logging.basicConfig(level=logging.DEBUG)
creds = Credentials(
username='mydomain\\my.name',
password='mypassword')
config = Configuration(server='exchange.xxx.local/EWS/Exchange.asmx', credentials=creds)
account = Account(
primary_smtp_address='my.name@mycompany.com',
credentials=creds,
autodiscover=False,
access_type=DELEGATE)
for item in account.inbox.all().order_by('-datetime_received')[:30]:
print(item.subject, item.body, item.attachments)启动脚本后,我在python控制台中得到以下输出:
DEBUG:exchangelib.protocol:Waiting for _protocol_cache_lock
DEBUG:exchangelib.protocol:Protocol __call__ cache miss. Adding key '('https://exchange.xxx.local/EWS/Exchange.asmx', Credentials('mydomain\\my.name', '********'), True)'
DEBUG:exchangelib.transport:Getting service auth type for https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:exchangelib.transport:Requesting b'<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><s:Header><t:RequestServerVersion Version="Exchange2016" /></s:Header><s:Body><m:ResolveNames ReturnFullContactData="false"><m:UnresolvedEntry>mydomain\\my.name</m:UnresolvedEntry></m:ResolveNames></s:Body></s:Envelope>' from https://exchange.xxx.local/EWS/Exchange.asmx
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): exchange.xxx.local
Traceback (most recent call last):
File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py", line 810, in _prepare_proxy
conn.connect()
File "C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connection.py", line 294, in connect
self._tunnel()
File "C:\seProg\python353\Lib\http\client.py", line 832, in _tunnel
message.strip()))
OSError: Tunnel connection failed: 407 Proxy Access Denied
... (and many more lines with error messages)我还尝试了exchangelib站点上的其他选项,使用autodiscover=True,只给出了creds= (不使用config=)。没有成功。然后,我从https://ewseditor.codeplex.com/安装了EWS-Editor,以便查看通过EWS的连接是否可以在我公司的环境中工作。它与该工具一起工作得很好,只需给它我的SMTP地址。
我将非常感谢任何人的帮助。提前感谢!
发布于 2017-07-11 05:33:57
你可能需要告诉exchangelib关于你的代理。您可以通过环境变量:https://github.com/ecederstrand/exchangelib/issues/123#issuecomment-295648189或自定义HTTPAdapter类:https://github.com/ecederstrand/exchangelib/issues/156#issuecomment-312391095来执行此操作
https://stackoverflow.com/questions/44764071
复制相似问题