Error “suds.transport.TransportError: HTTP Error 401: Unauthorized” using suds-py3 SOAP client in python3

大兔子大兔子 提交于 2021-01-29 17:48:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!