Python/exchangelib-无法建立连接
对不起,我的英语不太好: 在windows域中,我尝试使用pypi站点上给出的示例连接到我们的exchangeserver(2010/SP3):Python/exchangelib-无法建立连接,python,python-3.x,exchangewebservices,exchangelib,Python,Python 3.x,Exchangewebservices,Exchangelib,对不起,我的英语不太好: 在windows域中,我尝试使用pypi站点上给出的示例连接到我们的exchangeserver(2010/SP3): from exchangelib import DELEGATE, NTLM, Account, Credentials, Configuration import os, logging logging.basicConfig(level=logging.DEBUG) creds = Credentials( username='mydo
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)
DEBUG:exchangelib.protocol:正在等待\u protocol\u cache\u lock
调试:exchangelib。协议:协议调用缓存未命中。添加键“(”https://exchange.xxx.local/EWS/Exchange.asmx,凭据('mydomain\\my.name','********',True)'
调试:exchangelib.transport:获取的服务身份验证类型https://exchange.xxx.local/EWS/Exchange.asmx
调试:exchangelib.transport:从请求b'mydomain\\my.name'https://exchange.xxx.local/EWS/Exchange.asmx
调试:urllib3.connectionpool:启动新的HTTPS连接(1):exchange.xxx.local
回溯(最近一次呼叫最后一次):
文件“C:\CWS\Python venv\p353-01\lib\site packages\urlib3\connectionpool.py”,第594行,在urlopen中
自我准备代理(康涅狄格州)
文件“C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connectionpool.py”,第810行,在代理中
连接
文件“C:\CWS\Python-venv\p353-01\lib\site-packages\urllib3\connection.py”,第294行,在connect中
self._tunnel()
文件“C:\seProg\python353\Lib\http\client.py”,第832行,在_tunnel中
message.strip())
OS错误:隧道连接失败:407代理访问被拒绝
... (还有更多带有错误消息的行)
我还尝试了exchangelib站点中的其他选项,autodiscover=True,并且仅creds=given(不带config=)。没有成功。
然后,我从安装了EWS编辑器,以便查看通过EWS的连接在我公司的环境中是否可行。它可以很好地使用该工具,只需给它我的SMTP地址
我将非常感谢任何帮助。提前谢谢 您可能需要告诉exchangelib您的代理。您可以通过环境变量:或通过自定义的HTTPAdapter类:对此进行访问,您可能需要告诉exchangelib您的代理。您可以通过环境变量:或通过自定义HTTPAdapter类:来实现这一点:谢谢-我尝试了您的第一个建议,但没有成功(第二,我不知道如何构建HTTPAdapter类)。根据我的exchange和网络管理员的说法,这不是代理问题,因为在内部(域)通信中不需要使用代理:所有地址(如:*.xxx.local)都例外。我们的exchangeserver是“exchange.xxx.local”。我使用requests库用一个简单的
r=requests.get命令测试了这一点http://exchange.xxx.local)
它成功了!因此,无需使用代理-我希望得到另一个提示!请求.get('http://exchange.xxx.local“)
test不会触及TLS代码路径,而TLS代码路径正是发生错误的地方。尝试请求。获取('https://exchange.xxx.local/EWS/Exchange.asmx)
。否则,您可以在Thank you上尝试疑难解答部分-我尝试了您的第一个建议,但没有成功(第二,我不知道如何构建HTTPAdapter类)。根据我的exchange和网络管理员的说法,这不是代理问题,因为在内部(域)通信中不需要使用代理:所有地址(如:*.xxx.local)都例外。我们的exchangeserver是“exchange.xxx.local”。我使用requests库用一个简单的r=requests.get命令测试了这一点http://exchange.xxx.local)
它成功了!因此,无需使用代理-我希望得到另一个提示!请求.get('http://exchange.xxx.local“)
test不会触及TLS代码路径,而TLS代码路径正是发生错误的地方。尝试请求。获取('https://exchange.xxx.local/EWS/Exchange.asmx)
。否则,您可以尝试以下位置的疑难解答部分: