Python SOAP 泡沫和可怕的架构类型未找到错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4719854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 17:11:35  来源:igfitidea点击:

SOAP suds and the dreaded schema Type Not Found error

pythonsoapsuds

提问by dpjanes

I'm using the latest version of suds (https://fedorahosted.org/suds/) for the first time and I'm getting stalled at step one.

我第一次使用最新版本的 suds ( https://fedorahosted.org/suds/),但在第一步中我陷入了停滞。

suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'

Now, I know this is well covered ground in the suds world (https://fedorahosted.org/suds/wiki/TipsAndTricks#Schema-TypeNotFoundand Python/Suds: Type not found: 'xs:complexType') but this appears to slightly different because (a) schema is supposed to be automatically bound after version 0.3.4 and (b) even explicitly using the workaround, it still doesn't work.

现在,我知道这在 suds 世界(https://fedorahosted.org/suds/wiki/TipsAndTricks#Schema-TypeNotFoundPython/Suds: Type not found: 'xs:complexType')中得到了很好的覆盖,但这似乎略有不同,因为 (a) 架构应该在 0.3.4 版之后自动绑定,并且 (b) 即使明确使用变通方法,它仍然不起作用。

from suds.client import Client
from suds.xsd.sxbasic import Import

url = 'file:wsdl.wsdl'
Import.bind('http://schemas.xmlsoap.org/soap/encoding/')
client = Client(url, cache = None)

with the wsdl:

使用 wsdl:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://ws.client.com/Members.asmx"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://ws.client.com/Members.asmx"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://ws.client.com/Members.asmx">

      <s:element name="GetCategoriesResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="GetCategoriesResult">
              <s:complexType>
                <s:sequence>
                  <s:element ref="s:schema" />
                  <s:any />
                </s:sequence>
              </s:complexType>
            </s:element>
          </s:sequence>
        </s:complexType>
      </s:element>

    </s:schema>
  </wsdl:types>
</wsdl:definitions>

yields the exception above.

产生上面的异常。

采纳答案by Peter Lundberg

We got it working and I hope you did as well, even though it is a bit quirky. Perhaps an explicit location or filter will help. E.g.:

我们让它工作了,我希望你也这样做,尽管它有点古怪。也许明确的位置或过滤器会有所帮助。例如:

imp = Import(
    'http://schemas.xmlsoap.org/soap/encoding/',
    location='http://schemas.xmlsoap.org/soap/encoding/'
)
imp.filter.add('http://ws.client.com/Members.asmx')
client = Client(url, plugins=[ImportDoctor(imp)])

回答by tandy

I was banging my head for a while on this one. I finally resolved the issue by using the following syntax:

我在这个问题上撞了一段时间。我最终通过使用以下语法解决了这个问题:

from suds.xsd.doctor import ImportDoctor, Import

url = 'http://somedomain.com/filename.php?wsdl'
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('http://some/namespace/A')
doctor = ImportDoctor(imp)

client = Client(url, doctor=doctor)

Importantly, start with the url. Open that file in your browser and it will provide you with the wsdl definitions. Make sure you have the right url entered here and that an XML file actually opens. Also mind the ?wsdl at the end of the url.

重要的是,从 url 开始。在浏览器中打开该文件,它将为您提供 wsdl 定义。确保您在此处输入了正确的 url,并且实际打开了一个 XML 文件。还要注意网址末尾的 ?wsdl。

Second, imp = Import('http://schemas.xmlsoap.org/soap/encoding/')will import the standard SOAP schema.

其次,imp = Import('http://schemas.xmlsoap.org/soap/encoding/')将导入标准的 SOAP 模式。

Third, imp.filter.add('http:somedomain.com/A')will add your specific namespace. You can find this namespace location by opening the url you defined above in url=and looking for the section <wsdl:import namespace="http://somedomain.com/A".

第三,imp.filter.add('http:somedomain.com/A')将添加您的特定命名空间。您可以通过打开上面定义的 urlurl=并查找部分来找到此命名空间位置<wsdl:import namespace="http://somedomain.com/A"

Also be mindful of http vs https in your urls.

还要注意 url 中的 http 与 https。

回答by skyline75489

For those who still is troubled by this problem. This link https://bitbucket.org/jurko/suds/issue/20/typenotfound-schemamay provide useful information. The solution would be like this:

对于那些仍然被这个问题困扰的人。此链接https://bitbucket.org/jurko/suds/issue/20/typenotfound-schema可能会提供有用的信息。解决方案是这样的:

from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor

url = 'http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl'
imp = Import('http://www.w3.org/2001/XMLSchema',
    location='http://www.w3.org/2001/XMLSchema.xsd')
imp.filter.add('http://WebXml.com.cn/')
client = Client(url, doctor=ImportDoctor(imp))