Zeep PHP到Python SOAP请求

时间:2018-08-13 22:05:48

标签: php python soap zeep

我希望复制一些我在Python中使用的PHP代码。

因此,PHP代码生成以下SOAP请求

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns1="http://ws.apache.org/axis2">
    <SOAP-ENV:Body>
        <ns1:getKey>
            <ns1:user>USERNAME</ns1:user>
            <ns1:password>PASSWORD</ns1:password>
        </ns1:getKey>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这很好,但是,当尝试使用带有以下代码的Zeeps在Python中复制此代码时,出现如下所示的请求,有错误!

从zeep导入客户端 从lxml导入etree

class RemoveWSA():
  def egress(self, envelope, http_headers, operation, binding_options):
    envelope.find('{http://schemas.xmlsoap.org/soap/envelope/}Header').clear()
  def ingress(self, envelope, http_headers, operation):
      start = 1

#client = Client('http://www.maxbounty.com/api.cfc?wsdl', plugins=[RemoveWSA()])
client = Client('http://www.maxbounty.com/api.cfc?wsdl')

params = {"user":"USERNAME","password":"PASSWORD"}

#node = client.create_message(client.service, 'getKey', **params)

#print(etree.tostring(node, pretty_print=True))

result = client.service.getKey(**params)

#print(result)

结果:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <wsa:Action>urn:getKey</wsa:Action>
        <wsa:MessageID>urn:uuid:bd8376a3-adf6-4ae6-983c-2ebf83f2e934</wsa:MessageID>
        <wsa:To>http://www.maxbounty.com:80/api.cfc</wsa:To>
    </soap-env:Header>
    <soap-env:Body>
        <ns0:getKey xmlns:ns0="http://ws.apache.org/axis2">
            <ns0:user>USERNAME</ns0:user>
            <ns0:password>PASSWORD</ns0:password>
        </ns0:getKey>
    </soap-env:Body>
</soap-env:Envelope>

使用RemoveWSA函数创建以下内容(不确定入口函数的作用)

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"/>
    <soap-env:Body>
        <ns0:getKey xmlns:ns0="http://ws.apache.org/axis2">
            <ns0:user>USERNAME</ns0:user>
            <ns0:password>PASSWORD</ns0:password>
        </ns0:getKey>
    </soap-env:Body>
</soap-env:Envelope>

我该如何复制PHP请求并成功返回我在Python中从中获得的信息!

需要更多的代码示例让我知道!

欢呼

0 个答案:

没有答案