缺失类型命名空间 suds SOAP python
我正在尝试使用一个叫suds的Python库来创建一个SOAP请求。不过我有点卡住了。我查阅了其他相关的内容,但还是解决不了我的问题。看起来有一些类型在一个叫“ns1”的命名空间里缺失了。下面是我的代码:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
url = "https://relatics.relaticsonline.com/DataExchange.asmx?wsdl"
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
imp.filter.add('http://www.relatics.com/')
d = ImportDoctor(imp)
client = Client(url, doctor=d, location="https://rijkswaterstaat.relaticsonline.com/DataExchange.asmx")
print(client)
输出结果如下:
Service ( DataExchange ) tns="http://www.relatics.com/"
Prefixes (2)
ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
ns1 = "http://www.relatics.com/"
Ports (2):
(DataExchangeSoap)
Methods (2):
GetResult(xs:string Operation, Identification Identification, Parameters Parameters, Authentication Authentication)
Import(xs:string Operation, Identification Identification, Authentication Authentication, xs:string Filename, xs:string Data)
Types (48):
ns0:Array
ns0:ENTITIES
ns0:ENTITY
ns0:ID
ns0:IDREF
ns0:IDREFS
ns0:NCName
ns0:NMTOKEN
ns0:NMTOKENS
ns0:NOTATION
ns0:Name
ns0:QName
ns0:Struct
ns0:anyURI
ns0:arrayCoordinate
.....
在“ns1”这个命名空间里没有找到任何类型。所以我连请求都无法发出,因为我需要为身份验证/识别/参数创建一个对象。
我觉得可能是某种原因导致架构出了问题,但我就是搞不清楚。
1 个回答
2
它之所以没有成功,是因为SUDS只支持SOAP 1.0,而我尝试用的是SOAP 2.0。最后我通过发送一个原始的XML请求来解决了这个问题,具体代码如下:
raw_xml = """
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetResult xmlns="http://www.relatics.com/">
<Operation>%s</Operation>
<Identification>
<Identification>
<Workspace>%s</Workspace>
</Identification>
</Identification>
<Authentication>
<Authentication>
<Entrycode>%s</Entrycode>
</Authentication>
</Authentication>
</GetResult>
</soap:Body>
</soap:Envelope>"""
raw_xml = str.encode(raw_xml % (Operation, Workspace, Entrycode))
client = Client(url)
response = client.service.GetResult(__inject={'msg': raw_xml})