【问题标题】:How to handle python suds return return body[0].children如何处理python suds return return body[0].children
【发布时间】:2015-04-24 20:03:26
【问题描述】:

我正在使用连接到 MS Navision 2009 R2 Web 服务(SOAP api)的 python+suds 构建后端进程。

到目前为止一切都很好,这是我为初学者准备的:

from suds.client import Client
from suds.transport.https import WindowsHttpAuthenticated
ntlm = WindowsHttpAuthenticated(username='***\\***', password='*******')
url = 'http://host:7047/DynamicsNAV/WS/company/Page/Serial_Number_Information'
client = Client(url, transport=ntlm)
print (client)
try:
  result = client.service.Read(' ', ' ', 'value')
except WebFault, e:
  print e


print (result)

我遇到了以下 SOAP 回复的场景:

<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
<Soap:Body/>
</Soap:Envelope>

导致我的进程抛出以下错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/lib/python2.7/dist-packages/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/lib/python2.7/dist-packages/suds/client.py", line 647, in send
result = self.succeeded(binding, reply.message)
File "/usr/lib/python2.7/dist-packages/suds/client.py", line 684, in succeeded
reply, result = binding.get_reply(self.method, reply)
File "/usr/lib/python2.7/dist-packages/suds/bindings/binding.py", line 153, in get_reply
nodes = self.replycontent(method, soapbody)
File "/usr/lib/python2.7/dist-packages/suds/bindings/document.py", line 75, in replycontent
return body[0].children
AttributeError: 'NoneType' object has no attribute 'children'

我试过了

if not result:
  foo

和

if not key in result:
  foo

我不知道如何捕捉并摆脱这个错误。任何帮助表示赞赏。

【问题讨论】:

    标签: python api soap suds navision


    【解决方案1】:

    解决了。添加了第二个“例外”

    try:
      result = client.service.Read(' ', ' ', 'value')
    except WebFault, e:
      print e
    except AttributeError, e:
      print e
    

    【讨论】:

      猜你喜欢
      • 2014-05-01
      • 2010-10-07
      • 2015-10-02
      • 1970-01-01
      • 2014-03-15
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      相关资源
      最近更新 更多