SOAP suds 和可怕的模式 Type Not Found 错误

发布于 2024-10-12 11:49:31 字数 2248 浏览 3 评论 0 原文

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

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

现在,我知道这在泡沫世界中已经被广泛覆盖(https://fedorahosted. org/suds/wiki/TipsAndTricks#Schema-TypeNotFoundPython/Suds:未找到类型:'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)

使用 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>

会产生上述异常。

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.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-TypeNotFound and 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.

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:

<?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.

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

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

发布评论

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

评论(3

温柔戏命师 2024-10-19 11:49:31

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

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)

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

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

第三,imp.filter.add('http:somedomain.com/A') 将添加您的特定命名空间。您可以通过打开上面在 url= 中定义的 url 并查找

还要注意 url 中的 http 与 https。

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.

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

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".

Also be mindful of http vs https in your urls.

好久不见√ 2024-10-19 11:49:31

我们成功了,我希望你也能成功,尽管这有点奇怪。也许明确的位置或过滤器会有所帮助。例如:

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)])

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)])
夜光 2024-10-19 11:49:31

对于那些仍然被这个问题困扰的人。此链接 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))

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

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