Python SUDS SOAP请求到https服务401

use*_*303 6 python https suds

我正在尝试使用SUDS,并试图弄清楚为什么我无法使身份验证工作(或https).

我尝试访问的服务是通过https进行基本摘要式身份验证.根据调试,它似乎使用http而不是https.但不确定我错过了什么.任何线索都表示赞赏.

from suds.client import Client
from suds.transport.http import HttpAuthenticated
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)

def main():
    url = 'https://blah.com/soap/sp/Services?wsdl'
    credentials = dict(username='xxxx', password='xxxx')
    t = HttpAuthenticated(**credentials)
    client = Client(url, location='https://blah.com/soap/sp/Services', transport=t)
    print client.last_sent()

if __name__=="__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

调试输出:

DEBUG:suds.wsdl:阅读wsdl at:https://blah.com/soap/sp/Services wsdl ... DEBUG:suds.transport.http:opening(https://blah.com/soap/sp/服务?wsdl)
snip ...
文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\reader.py",第95行,下载
fp = self.options.transport.open (请求(URL))

文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py",第173行,打开
返回HttpTransport.open(self,request)

文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py",第64行,在open中
引发TransportError(str(e),e.code,e.fp )

suds.transport.TransportError:HTTP错误401:需要授权

DRH*_*DRH 7

Suds提供两个HttpAuthenticated类,一个在suds.transport.http模块中,另一个在suds.transport.https模块中.它似乎是您实例化的suds.transport.http,但是,由于您的URL https://,您可能想尝试suds.transport.https.HttpAuthenticated.


Dan*_*eis 5

我偶然发现了这个问题并找到了适合我的解决方案.我的服务器使用的是NTLM身份验证,因此suds要使用它,我只需要按照文档中的"Windows(NTLM)"部分进行操作.

首先安装python-ntlm,然后你可以写:

from suds.transport.https import WindowsHttpAuthenticated
ntlm = WindowsHttpAuthenticated(username='xx', password='xx')
client = Client(url, transport=ntlm)
Run Code Online (Sandbox Code Playgroud)