2012-01-02 83 views
5

我正在尝试使用SUDS,并试图弄清楚为什么我无法获得身份验证工作(或https)。Python SUDS对https服务的SOAP请求401

我试图访问的服务是基于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() 

调试输出:

DEBUG:suds.wsdl:reading wsdl at: https://blah.com/soap/sp/Services?wsdl ... DEBUG:suds.transport.http:opening (https://blah.com/soap/sp/Services?wsdl)
snip ...
File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\reader.py", line 95, in download
fp = self.options.transport.open(Request(url))

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 173, in open
return HttpTransport.open(self, request)

File "C:\Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py", line 64, in open
raise TransportError(str(e), e.code, e.fp)

suds.transport.TransportError: HTTP Error 401: Authorization Required

+0

首先正确性......应该只是“摘要式身份验证”而不是“基本摘要式身份验证”。 auth的类型是:'digest'和'basic'。所以我很困惑。 – user9303 2012-01-02 20:55:44

回答

6

泡沫提供了两个HttpAuthenticated类,一个所述suds.transport.http模块中,第二个suds.transport.https模块中。它似乎是从suds.transport.http实例化的,但由于您的网址是https://,因此您可能需要尝试suds.transport.https.HttpAuthenticated

+0

+1。 'suds.transport.https.HttpAuthenticated'不在suds'doc中。您的解决方案是我的问题的答案。 – 2015-10-15 18:11:20

5

我偶然发现了这个问题,并找到了适用于我的解决方案。 我的服务器正在使用NTLM身份验证,因此要使suds与之配合使用,我只需要按照documentation中的“Windows(NTLM)”部分进行操作。

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

from suds.transport.https import WindowsHttpAuthenticated 
ntlm = WindowsHttpAuthenticated(username='xx', password='xx') 
client = Client(url, transport=ntlm)