使用Python的WSDL服务,是我的客户端代码还是服务器代码?

发布于 2024-09-14 12:34:18 字数 2299 浏览 4 评论 0原文

我正在尝试为 WSDL 服务编写一个 Python 客户端。我正在使用 Suds 库来处理 SOAP 消息。

当我尝试调用该服务时,出现 Suds 异常: not returned to message part。如果我设置了 retxml Suds 选项,我会得到对我来说看起来不错的 XML。

是客户端代码有问题吗?我是否缺少一些允许 Suds 正确解析 XML 的标志?或者,问题可能出在服务器上。 XML 的结构是否不正确?

我的代码如下(方法名称已更改):

c = Client(url)  
p = c.factory.create('MyParam')  
p.value = 100  
c.service.run(p)  

这会导致 Suds 异常:

File "/home/.../test.py", line 38, in test  
res = self.client.service.run(p)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 539, in __call__
return client.invoke(args, kwargs)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 598, in invoke
result = self.send(msg)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 627, in send  
result = self.succeeded(binding, reply.message)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line   659, in succeeded  
r, p = binding.get_reply(self.method, reply)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/bindings/binding.py", line 151, in get_reply  
result = self.replycomposite(rtypes, nodes)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-  py2.6.egg/suds/bindings/binding.py", line 204, in replycomposite  
raise Exception('<%s/> not mapped to message part' % tag)  
Exception: <rval/> not mapped to message part  

返回的 XML(已修改以删除客户标识符)

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:getResponse xmlns:ns2="http://api.xxx.xxx.com/api/">
      <rval xmlns="http://xxx.xxx.xxx.com/api/">
        <ns2:totalNumEntries>
          2
        </ns2:totalNumEntries>
        <ns2:entries>
          <ns2:id>
            1
          </ns2:id>
        </ns2:entries>
        <ns2:entries>
          <ns2:id>
            2
          </ns2:id>
        </ns2:entries>
      </rval>
    </ns2:getResponse>
  </S:Body>
</S:Envelope>

I'm trying to write a Python client for a a WSDL service. I'm using the Suds library to handle the SOAP messages.

When I try to call the service, I get a Suds exception: <rval /> not mapped to message part. If I set the retxml Suds option I get XML which looks OK to me.

Is the problem with the client code? Am I missing some flag which will allow Suds to correctly parse the XML? Alternatively, the problem could be with the server. Is the XML not structured correctly?

My code is a follows (method names changed):

c = Client(url)  
p = c.factory.create('MyParam')  
p.value = 100  
c.service.run(p)  

This results in a Suds exception:

File "/home/.../test.py", line 38, in test  
res = self.client.service.run(p)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 539, in __call__
return client.invoke(args, kwargs)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 598, in invoke
result = self.send(msg)
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line 627, in send  
result = self.succeeded(binding, reply.message)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/client.py", line   659, in succeeded  
r, p = binding.get_reply(self.method, reply)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-py2.6.egg/suds/bindings/binding.py", line 151, in get_reply  
result = self.replycomposite(rtypes, nodes)  
File "/usr/local/lib/python2.6/dist-packages/suds-0.3.9-  py2.6.egg/suds/bindings/binding.py", line 204, in replycomposite  
raise Exception('<%s/> not mapped to message part' % tag)  
Exception: <rval/> not mapped to message part  

The returned XML (modified to remove customer identifiers)

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:getResponse xmlns:ns2="http://api.xxx.xxx.com/api/">
      <rval xmlns="http://xxx.xxx.xxx.com/api/">
        <ns2:totalNumEntries>
          2
        </ns2:totalNumEntries>
        <ns2:entries>
          <ns2:id>
            1
          </ns2:id>
        </ns2:entries>
        <ns2:entries>
          <ns2:id>
            2
          </ns2:id>
        </ns2:entries>
      </rval>
    </ns2:getResponse>
  </S:Body>
</S:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有心的人 2024-09-21 12:34:18

泡沫的可能重复意思是“未映射到消息部分”?

这是我对这个问题的回答:

我遇到了类似的问题,调用成功,Suds 在解析客户端的响应时崩溃了。我使用的解决方法是使用 Suds 选项返回原始 XML ,然后使用 BeautifulSoup 解析响应。

例子:

client = Client(url)
client.set_options(retxml=True)
soapresp_raw_xml = client.service.submit_func(data)
soup = BeautifulStoneSoup(soapresp_raw_xml)
value_i_want = soup.find('ns:NewSRId')

Possible dup of What does suds mean by "<faultcode/> not mapped to message part"?

Here is my answer from that question:

I had a similar issue where the call was successful, and Suds crashed on parsing the response from the client. The workaround I used was to use the Suds option to return raw XML and then use BeautifulSoup to parse the response.

Example:

client = Client(url)
client.set_options(retxml=True)
soapresp_raw_xml = client.service.submit_func(data)
soup = BeautifulStoneSoup(soapresp_raw_xml)
value_i_want = soup.find('ns:NewSRId')
冷血 2024-09-21 12:34:18

此异常实际上意味着 SOAP 服务的答案包含标记 ,该标记在服务的 WSDL 方案中不存在。

请记住,Suds 库会缓存 WSDL 方案,这就是如果最近更改 WSDL 方案可能会出现问题的原因。然后答案与新方案匹配,但由 suds-client 使用旧方案进行验证。在这种情况下,rm /tmp/suds/*将为您提供帮助。

This exception actually means that the answer from SOAP-service contains tag <rval>, which doesn't exist in the WSDL-scheme of the service.

Keep in mind that the Suds library caches the WSDL-scheme, that is why the problem may occur if the WSDL-scheme was changed recently. Then the answers match the new scheme, but are verified by the suds-client with the old one. In this case rm /tmp/suds/* will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文