Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

soap

suds

I'm using suds for the first time and trying to communicate with a server hosted by an external company. When I call a method on the server I get this XML back.

<?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>

The exception thrown is this:


  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

Any idea why suds is throwing the exception? Any thoughts on how it could be fixed?

like image 969
Pratik Patel Avatar asked Oct 15 '22 05:10

Pratik Patel


2 Answers

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')
like image 63
JiminyCricket Avatar answered Oct 18 '22 09:10

JiminyCricket


Already answered here: What does suds mean by "<faultcode/> not mapped to message part"?

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

Keep in mind that 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.

like image 36
denis-sumin Avatar answered Oct 18 '22 07:10

denis-sumin