Suds:响应中找不到类型

时间:2011-04-13 19:51:45

标签: python types wsdl response suds

我很难获得基于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

非常感谢任何解决此问题的帮助。

2 个答案:

答案 0 :(得分:6)

这可能是ImportDoctor的工作。在破坏的WSDL上运行是非常常见的。

试试这个:

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)

答案 1 :(得分:2)

通过联系WSDL提供程序并要求他修复(损坏的)WSDL,已解决此问题。不幸的是,我不知道任何基于代码的解决方案。