Python SUDS 在调用中不包含参数



我是Python和suds的新手。使用SOAP UI,对我的服务的调用如下所示:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns="<URL to service>" 
    xmlns:ns1="<URL to second namespace>">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:AuthenticateCaller>
         <!--Optional:-->
         <ns:request>
            <ns1:LoanAccountNumber>292206816</ns1:LoanAccountNumber>
         </ns:request>
      </ns:AuthenticateCaller>
   </soapenv:Body>
</soapenv:Envelope>

我尝试了以下使用泡沫:

from suds.xsd.doctor import ImportDoctor, Import
imp = Import(<URL to service>)
imp.filter.add(<URL to second namespace>)
doctor = ImportDoctor(imp)
client = Client(url, doctor=doctor)
client.service.AuthenticateCaller(LoanAccountNumber='292206816')

生成的XML如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
    xmlns:ns0="<URL to service>" 
    xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns0:AuthenticateCaller/>
   </ns1:Body>
</SOAP-ENV:Envelope>

调用中缺少LoanCountNumber参数,该参数是API的密钥。它还缺少我认为ImportDoctor应该修复的第二个命名空间。

我的问题是,对API的调用中不包括LoanCountNumber,我错过了什么。

以下说明似乎会对您有所帮助:

首先,您必须打印您的Client即时消息,也就是代码中的client,所以您会看到这样的消息:

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913
Service ( YourService_cmV6YW9ubGluZS5uZXQ= )  tns="http://www.yourservice.com/soap/YourService_cmV6YW9ubGluZS5uZXQ="
   Prefixes (1)
  ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
   Ports (1):
  (YourService_cmV6YW9ubGluZS5uZXQ=Port)
     Methods (2):
        your_method(xs:string _your_param)
     Types (48):
        ns0:Array
        ns0:ENTITIES
        ns0:ENTITY
        ns0:ID
        ns0:NOTATION
        ns0:Name
        ns0:QName
        ns0:Struct
        ns0:anyURI
        ns0:arrayCoordinate
        ns0:base64
        ns0:base64Binary
        ns0:boolean
        ns0:byte
        ns0:date
        ns0:dateTime
        ns0:decimal
        ns0:double
        ns0:duration
        ns0:float
        ns0:hexBinary
        ns0:int
        ns0:integer
        ns0:language
        ns0:long
        ns0:negativeInteger
        ns0:positiveInteger
        ns0:short
        ns0:string
        ns0:time
        ns0:token

然后找到合适的参数类型,并以以下方式创建参数:

your_param = client.factory.create("ns0:string")
your_param.value = your_value

(复杂类型遵循复杂方式!)

现在,您可以如下调用您的方法:

client.service.your_method(your_param)

尽情享受吧!

最新更新