缺少类型命名空间suds SOAP python

时间:2014-10-30 19:39:07

标签: python soap suds

我试图用suds创建一个SOAP请求,这是一个python库。但是,我有点卡住了。我已经研究过有关此问题的其他主题。但无法解决我的问题。似乎命名空间(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 个答案:

答案 0 :(得分: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})