我第一次使用suds并尝试与外部公司托管的服务器进行通信。当我在服务器上调用一个方法时,我得到了这个XML。
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Can't use string ("") as an ARRAY ref while "strict refs" in use at /vindicia/site_perl/Vindicia/Soap/DocLitUtils.pm line 130.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
引发的异常是:
File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\client.py", line 538, in __call__ return client.invoke(args, kwargs) File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\client.py", line 602, in invoke result = self.send(msg) File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\client.py", line 634, in send result = self.succeeded(binding, reply.message) File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\client.py", line 669, in succeeded r, p = binding.get_reply(self.method, reply) File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\bindings\binding.py", line 157, in get_reply result = self.replycomposite(rtypes, nodes) File "C:\Python26\lib\site-packages\suds-0.4-py2.6.egg\suds\bindings\binding.py", line 227, in replycomposite raise Exception(' not mapped to message part' % tag) Exception: 'faultcode' not mapped to message part
知道为什么suds会抛出异常吗?有关它如何修复的任何想法?
答案 0 :(得分:2)
我有一个类似的问题,呼叫成功,并且suds在解析来自客户端的响应时崩溃。我使用的解决方法是使用suds option to return raw 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')
答案 1 :(得分:0)
这里已经回答:What does suds mean by "<faultcode/> not mapped to message part"?
此异常实际上意味着SOAP-service的答案包含标记<faultcode>
,该标记在服务的WSDL方案中不存在。
请记住,suds库缓存了WSDL方案,这就是为什么如果最近更改了WSDL方案可能会出现问题的原因。然后答案与新方案匹配,但由suds-client验证旧方案。在这种情况下,rm /tmp/suds/*
会对您有所帮助。