编程语言
首页 > 编程语言> > python – Suds:响应中找不到类型

python – 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.

任何帮助解决这个问题将不胜感激.

解决方法:

这可能是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)

标签:python,types,wsdl,response,suds
来源: https://codeday.me/bug/20190610/1211140.html