我很难让基于 suds 的 python SOAP 客户端解析响应:客户端构造正确并且解析 WSDL 就好了。据我所知,WSDL 中没有导入,所以这似乎不是一个典型的ImportDoctor
问题。
来自 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>
我的代码:
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)
最后一行抛出此异常:
...
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/, )'
我的理解是,webservice 返回一个对象数组FontType
(即FontType[]
),如getFontResponse
方法中所指定,但未能定义FontType[]
类型,而仅描述FontType
.
任何解决此问题的帮助将不胜感激。