Suds:响应中未找到类型

发布于 2024-11-01 11:06:08 字数 2163 浏览 1 评论 0原文

我很难让基于 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/, )'

我的理解是,Web 服务返回一个 FontType 对象数组(即 FontType[]),如下所示在 getFontResponse 方法中指定,但未定义 FontType[] 类型,仅描述 FontType

任何解决此问题的帮助将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖鼻大婶 2024-11-08 11:06:08

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

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)
浅浅 2024-11-08 11:06:08

通过联系 WSDL 提供商并要求他修复(损坏的)WSDL,该问题已得到解决。不幸的是,我不知道这个问题有任何基于代码的解决方案。

This issue has been resolved by contacting the WSDL provider and asking him to fix the (broken) WSDL. Unfortunately I'm unaware of any code-based solutions to this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文