我正在使用最新版本的肥皂水(https://fedorahosted.org/suds/ https://fedorahosted.org/suds/)第一次,我在第一步就停滞了。
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
现在,我知道这是泡沫世界中被充分覆盖的地面(https://fedorahosted.org/suds/wiki/TipsAndTricks#Schema-TypeNotFound https://fedorahosted.org/suds/wiki/TipsAndTricks#Schema-TypeNotFound and Python/Suds:找不到类型:'xs:complexType' https://stackoverflow.com/questions/1329190/python-suds-type-not-found-xscomplextype)但这似乎略有不同,因为 (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>
产生上面的异常。
我在这个问题上敲了一段时间的头。我最终使用以下语法解决了该问题:
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。
Second, imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
将导入标准 SOAP 模式。
Third, imp.filter.add('http:somedomain.com/A')
将添加您的特定名称空间。您可以通过打开上面定义的 url 来找到此命名空间位置url=
并寻找该部分<wsdl:import namespace="http://somedomain.com/A"
.
还要注意 url 中的 http 与 https。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)