使用 suds SOAP 库进行 HTTP 身份验证的奇怪行为

2024-05-16

我有一个正在运行的 python 程序,它使用 suds 通过 SOAP 获取大量数据。 Web服务是通过分页功能实现的,这样我就可以抓取nnn每个 fetch 调用的行并获取下一个nnn与后续的电话。如果我使用如下代码向 HTTP 服务器进行身份验证



client = suds.client.Client(url=url, location=location, username=username, password=password, timeout=timeout)
  

一切都很好。但是,如果我使用以下内容



t = suds.transport.https.HttpAuthenticated(username=username, password=password)
t.handler = urllib2.HTTPBasicAuthHandler(t.pm)
t.urlopener = urllib2.build_opener(t.handler)
client = suds.client.Client(url=url, location=location, timeout=timeout, transport=t) 
  

它恰好适用于 6 次迭代。也就是说,如果我指定每次提取 10 行的提取限制,我会返回 60 行。在第七次获取时,我收到



  File "build/bdist.linux-i686/egg/suds/client.py", line 542, in __call__
  File "build/bdist.linux-i686/egg/suds/client.py", line 602, in invoke
  File "build/bdist.linux-i686/egg/suds/client.py", line 649, in send
  File "build/bdist.linux-i686/egg/suds/client.py", line 698, in failed
AttributeError: 'NoneType' object has no attribute 'read'
  

有谁对可能导致此问题的原因有任何建议。肯定是这个变化导致了问题。我可以来回交换身份验证样式,并且它是完全可复制的。

我正在运行 python 2.6.6 和 suds 0.4。

Thanks


问题似乎是urllib2.HTTPError是从较低的水平上提高的,其fp属性为无:

81号线suds.transport.http:

except u2.HTTPError, e:
    if e.code in (202,204):
        result = None
    else:
        raise TransportError(e.msg, e.code, e.fp)

该异常最终被传递到第 698 行suds.client在那里error.fp.read()线路爆炸:

def failed(self, binding, error):
    status, reason = (error.httpcode, tostr(error))
    reply = error.fp.read()

我建议猴子修补suds.SoapClient类来获取 HTTP 错误代码和消息。在构建之前添加这些行suds.Client,然后运行它以查看第 7 次提取引发的 HTTP 错误:

class TestClient(suds.client.SoapClient):
    def failed(self, binding, error):
        print error.httpcode, error.args

suds.client.SoapClient = TestClient
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 suds SOAP 库进行 HTTP 身份验证的奇怪行为 的相关文章

随机推荐