尝试使用suds和ewsclient在python 3中编写客户端以连接到Exchange Web服务。我已经使用以下CURL命令检查了与WSDL URL的连接:
curl -u username:password -L https://exchange_server/EWS/Services.wsdl -H "Content-Type:text/xml" --ntlm
我使用上面的命令返回了WSDL xml模式。
我的客户代码是:
def test_client():
#variables defined, can't disclose
transport = WindowsHttpAuthenticated(username=username, password=password)
cred_str = ('%s:%s' % (username, password)).replace('\n', '')
base64string = str(base64.b64encode(bytes(cred_str,'utf-8')))
authenticationHeader = {"SOAPAction" : "ActionName", "Authorization" : "%s" % base64string}
client = suds.client.Client(url=wsdl_url, transport=transport, headers=authenticationHeader, plugins=[ewsclient.AddService()])
return client
print(test_client())
但是我得到这个错误:
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 401: Unauthorized
我已经遇到了类似的问题,但是并没有完全解决我的问题:
有人可以告诉我我做错了什么吗?用户名/密码和服务器详细信息正确时,为什么会显示授权错误?