问题
Trying to write a client in python 3 using suds and ewsclient in order to connect to the Exchange Web Services. I have checked my connection to the WSDL URL using the below CURL command:
curl -u username:password -L https://exchange_server/EWS/Services.wsdl -H "Content-Type:text/xml" --ntlm
I got back the WSDL xml schema using the above command.
My client code is:
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())
But I get this error:
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 401: Unauthorized
I've already gone through a similar question, but doesn't quite address my issue:
Python SOAP client, WSDL call with suds gives Transport Error 401 Unauthorized for HTTP basic authentication
Can someone please tell me what I'm doing wrong? Why it is giving a authorization error when the username/password and the server details is correct ?
来源:https://stackoverflow.com/questions/63545453/error-suds-transport-transporterror-http-error-401-unauthorized-using-suds-p