背景
我正在用 python 2.7.3 构建一个 SOAP 客户端,并使用 Canonical 提供的 suds 0.4.1 库。服务器正在通过 HTTPS 使用基本身份验证。
问题
无法通过服务器上的身份验证,甚至无法访问 WSDL。我收到以下错误:
suds.transport.TransportError:HTTP 错误 401:未经授权
尝试解析和代码
我已经尝试了suds 文档中描述的两种身份验证方法,但仍然出现上述错误client = Client(url, ...)
。我已经确认了在网络浏览器中连接的凭据和能力,这工作正常。
在声明wsdl_url
, username
and之后password
,我尝试了:
client = Client(url=wsdl_url, username=username, password=password)
# as well as:
t = HttpAuthenticated(username=username, password=password)
client = Client(url=wsdl_url, transport=t)
# and even:
t = HttpAuthenticated(username=username, password=password)
t.handler = urllib2.HTTPBasicAuthHandler(t.pm)
t.urlopener = urllib2.build_opener(t.handler)
client = Client(url=wsdl_url, transport=t)
最后一个似乎至少从 WSDL URL 中得到了另一个关于 HTTP authentication with suds的问题的响应。
其他注意事项
这个问题与这个类似的问题不同,因为我使用的是:
from suds.transport.https import HttpAuthenticated
# not:
# from suds.transport.http import HttpAuthenticated
并且从 Traceback 中,client = Client(url, ...)
电话明显命中 suds.transport.https.py:
File "/usr/lib/python2.7/dist-packages/suds/client.py", line 112, in __init__ self.wsdl = reader.open(url)
File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 152, in open d = self.fn(url, self.options)
File "/usr/lib/python2.7/dist-packages/suds/wsdl.py", line 136, in __init__ d = reader.open(url)
File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 79, in open d = self.download(url)
File "/usr/lib/python2.7/dist-packages/suds/reader.py", line 95, in download fp = self.options.transport.open(Request(url))
File "/usr/lib/python2.7/dist-packages/suds/transport/https.py", line 60, in open return HttpTransport.open(self, request)
File "/usr/lib/python2.7/dist-packages/suds/transport/http.py", line 64, in open raise TransportError(str(e), e.code, e.fp)
我错过了什么?