I'm having a hard time getting a python SOAP client based on suds to parse a response: the client is constructed correctly and parses the WSDL just fine. As far as I can see there are no imports in the WSDL, so this doesn't seem like a typical ImportDoctor
issue.
Relevant bits from the WSDL:
<xsd:complexType name="getFontsRequest">
<xsd:sequence>
<xsd:element name="UserID" type="xsd:int" maxOccurs="1" minOccurs="1"></xsd:element>
<xsd:element name="TAWSAccessKey" type="xsd:string" maxOccurs="1" minOccurs="1"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getFontsResponse">
<xsd:sequence>
<xsd:element name="UserID" type="xsd:int"></xsd:element>
<xsd:element name="Status" type="xsd:string"></xsd:element>
<xsd:element name="Fonts" type="tns:FontType[]"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="FontType">
<xsd:sequence>
<xsd:element name="ID" type="xsd:int"></xsd:element>
<xsd:element name="Name" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
My Code:
self.soap_client = Client(settings.WSDL_URL)
self.factory = self.soap_client.factory
self.service = self.soap_client.service
# ...
getFontsRequest = self.factory.create('getFontsRequest')
getFontsRequest.UserID = settings.WS_UID
getFontsRequest.TAWSAccessKey = settings.WS_KEY
self.service.getFonts(getFontsRequest)
The last line throws this exception:
...
File "/usr/local/Cellar/python/2.7.1/lib/python2.7/site-packages/suds/xsd/sxbasic.py", line 63, in resolve
raise TypeNotFound(qref)
TypeNotFound: Type not found: '(FontType[], http://www.type-applications.com/character_set/, )'
My understanding is that the webservice returns an array of FontType
objects (i.e. FontType[]
), as specified in the getFontResponse
method, but fails to define the FontType[]
type, and merely describes FontType
.
Any help to resolve this would be greatly appreciated.
This might be a job for the ImportDoctor
. It's surprisingly common to run across broken WSDLs.
Try this:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
wsdl_url = settings.WSDL_URL
# Fix missing types with ImportDoctor
schema_url = 'http://www.type-applications.com/character_set/'
schema_import = Import(schema_url)
schema_doctor = ImportDoctor(schema_import)
# Pass doctor to Client
client = Client(url=wsdl_url, doctor=schema_doctor)