SOAP suds和可怕的架构Type Not Found错误

dpj*_*nes 16 python soap suds

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

suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
Run Code Online (Sandbox Code Playgroud)

现在,我知道这在泡沫世界中有很好的覆盖面(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)
Run Code Online (Sandbox Code Playgroud)

与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>
Run Code Online (Sandbox Code Playgroud)

产生上述例外.

tan*_*ndy 18

我在这一个上敲了一会儿.我最终使用以下语法解决了该问题:

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)
Run Code Online (Sandbox Code Playgroud)

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

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

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

还要注意网址中的http vs https.


小智 11

我们得到了它的工作,我希望你做得很好,即使它有点古怪.也许明确的位置或过滤器会有所帮助.例如:

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)])
Run Code Online (Sandbox Code Playgroud)


sky*_*489 6

对于那些仍然困扰这个问题的人.这个链接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))
Run Code Online (Sandbox Code Playgroud)