Python SUDS SOAP请求到https服务401

时间:2012-01-02 03:40:02

标签: 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()

调试输出:

  

DEBUG:suds.wsdl:在https://blah.com/soap/sp/Services?wsdl阅读wsdl ...   DEBUG:suds.transport.http:opening(https://blah.com/soap/sp/Services?wsdl)   
剪辑...
   文件" C:\ Python27 \ Lib \ site-packages \ suds-0.4-py2.7 \ suds \ reader.py",第95行,下载
    fp = self.options.transport.open(Request(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行,在打开时提出TransportError( str(e),e.code,e.fp)

     

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

2 个答案:

答案 0 :(得分:7)

Suds提供了两个HttpAuthenticated类,一个在suds.transport.http模块中,另一个在suds.transport.https模块中。它似乎是您从suds.transport.http实例化的,但由于您的网址为https://,您可能需要尝试suds.transport.https.HttpAuthenticated

答案 1 :(得分:5)

我偶然发现了这个问题并找到了适合我的解决方案。 我的服务器正在使用NTLM身份验证,因此suds使用它时,我只需要关注" Windows(NTLM)" documentation中的部分。

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

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