简体   繁体   English

Python SUDS SOAP请求到https服务401

[英]Python SUDS SOAP request to https service 401

I am trying use SUDS and am stuck trying to figure out why I can't get authentication to work (or https). 我正在尝试使用SUDS,并试图弄清楚为什么我无法使身份验证工作(或https)。

The service I am trying to access is over https with basic digest authentication. 我尝试访问的服务是通过https进行基本摘要式身份验证。 Based on the debugs it seems to be using http instead of https. 根据调试,它似乎使用http而不是https。 But not really sure what I am missing. 但不确定我错过了什么。 Any clue is appreciated. 任何线索都表示赞赏。

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 Output: 调试输出:

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) DEBUG:suds.wsdl:阅读wsdl at: https ://blah.com/soap/sp/Services wsdl ... DEBUG:suds.transport.http:opening(https://blah.com/soap/sp/服务?WSDL)
snip ... 剪...
File "C:\\Python27\\Lib\\site-packages\\suds-0.4-py2.7\\suds\\reader.py", line 95, in download 文件“C:\\ Python27 \\ Lib \\ site-packages \\ suds-0.4-py2.7 \\ suds \\ reader.py”,第95行,下载
fp = self.options.transport.open(Request(url)) 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 文件“C:\\ Python27 \\ Lib \\ site-packages \\ suds-0.4-py2.7 \\ suds \\ transport \\ http.py”,第173行,打开
return HttpTransport.open(self, request) 返回HttpTransport.open(self,request)

File "C:\\Python27\\Lib\\site-packages\\suds-0.4-py2.7\\suds\\transport\\http.py", line 64, in open 文件“C:\\ Python27 \\ Lib \\ site-packages \\ suds-0.4-py2.7 \\ suds \\ transport \\ http.py”,第64行,打开
raise TransportError(str(e), e.code, e.fp) 提出TransportError(str(e),e.code,e.fp)

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

Suds provides two HttpAuthenticated classes, one in the suds.transport.http module and the second in the suds.transport.https module. HttpAuthenticated提供了两个HttpAuthenticated类,一个在suds.transport.http模块中,另一个在suds.transport.https模块中。 It appears your instantiating from suds.transport.http , however since your URL is https:// , you may want to try suds.transport.https.HttpAuthenticated . 它似乎是你从suds.transport.http实例化的,但是由于你的URL是https:// ,你可能想尝试suds.transport.https.HttpAuthenticated

I stumbled upon this problem and found a solution that works for me. 我偶然发现了这个问题并找到了适合我的解决方案。 My server was using NTLM authentication, so for suds to work with it, I just had to follow the "Windows (NTLM)" section in the documentation . 我的服务器正在使用NTLM身份验证,因此对于使用它的suds ,我只需要遵循文档中的“Windows(NTLM)”部分。

First install python-ntlm , and then you can write: 首先安装python-ntlm ,然后你可以写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM