Patching suds to support recursive WSDL

To homepage

Sad as it may be, there are still many online service providers who expose their API to clients through SOAP. SOAP is so antithetical to the spirit and zen of python that most of the python SOAP client libraries are abandoned.

No matter, some of us don’t have the luxury to choose the third party service provider they will be integrating with. Among those unfortunate are myself; I’ve had to integrate with an API which none of the available python SOAP libraries – actively maintained or abandoned – could understand. The problem was that attempting to read the WSDL file for the service either led to exceptions or led to incorrectly defined generated classes that inaccurately mapped to the API I am trying to use. I’ve tried several libraries including: SoapBox, ZSI, spyne, SOAPpy, and suds. Moreover, this problem did not happen when using Java or C# SOAP clients, those seemed to read the WSDL and interact with the SOAP endpoint just fine.

I was close to giving up on using a true SOAP client in python, the alternative being to just issue hand-written templated XML posts to the SOAP endpoint and parsing the response. That process made me want to rip out my heart with my bare hands, so I decided to dig into one of the libraries by random, in particular I looked into suds. When that library attempted to read the WSDL of the service provider I’m working with, it threw a RuntimeError: maximum recursion depth exceeded error. Upon digging into the code and the WSDL file, I found out that the main WSDL file was importing an intermediary WSDL file, which in turn was importing a bunch of other WSDL files, two of which were importing each other, leading to an infinite recursive loop when suds attempted to parse the file.

The solution was to change the parser so that it keeps a cached reference to each WSDL Schema file keyed by the name of the import, so that it does not attempt to rebuild the same schema file over and over when it see the same import, which is what leads to the recursive loop. I’ve patched the suds library and created a fork on my own github with the patch since suds seems not to be activey maintained anymore. There is even a five years old ticket which I found after making the patch which addresses this exact issue. The patches proposed in the ticket seem to propose solutions, but I disagree with them since they seem to restrict the recursive depth of WSDL, which is unnecessary in my opinion.

Patched suds: