【问题标题】:Python SUDS SOAP request to https service 401Python SUDS SOAP 请求到 https 服务 401
【发布时间】:2012-01-31 14:29:39
【问题描述】:

我正在尝试使用 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 ... 调试: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 行,打开
return 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:需要授权

【问题讨论】:

  • 首先为了正确...应该只是“摘要式身份验证”而不是“基本摘要式身份验证”。 auth 的类型有:“digest”和“basic”。所以我很困惑。

标签: python https suds


【解决方案1】:

Suds 提供了两个HttpAuthenticated 类,一个在suds.transport.http 模块中,第二个在suds.transport.https 模块中。看来您是从 suds.transport.http 实例化的,但是由于您的 URL 是 https://,您可能想尝试 suds.transport.https.HttpAuthenticated

【讨论】:

  • +1。 suds.transport.https.HttpAuthenticated 不在 suds 的文档中。你的解决方案就是我的问题的答案。
【解决方案2】:

我偶然发现了这个问题,并找到了适合我的解决方案。 我的服务器使用的是 NTLM 身份验证,所以要让suds 使用它,我只需要遵循documentation 中的“Windows (NTLM)”部分即可。

先安装python-ntlm,然后就可以写了:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多