在python3中使用suds-py3 SOAP客户端的错误“ suds.transport.TransportError:HTTP错误401:未经授权”

时间:2020-08-23 09:33:31

标签: python-3.x soap exchangewebservices suds

尝试使用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

我已经遇到了类似的问题,但是并没有完全解决我的问题:

Python SOAP client, WSDL call with suds gives Transport Error 401 Unauthorized for HTTP basic authentication

有人可以告诉我我做错了什么吗?用户名/密码和服务器详细信息正确时,为什么会显示授权错误?

0 个答案:

没有答案