我正在尝试使用一个特别神秘的 WSDL SOAP 服务,在此处发布:
https://api.business.govt.nz/registry/resource/_system/governance/apimgt/applicationdata/provider/mbiecreator/DiscussionCorrespondence/v1/documentation/files/DiscussionCorrespondence.zip

该文档提供了一个示例 Soap 查询:

<soapenv:Envelope xmlns:list="http://www.iponz.govt.nz/XMLSchema/Discussion/List" xmlns:ser="http://www.iponz.govt.nz/services" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
 <soapenv:Header/>
 <soapenv:Body>
  <ser:getDiscussionList>
   <list:Transaction>
    <list:DiscussionTransactionBody>
     <list:TransactionContentDetails>
      <list:TransactionCode>Get Discussion List</list:TransactionCode>
      <list:TransactionData>
       <list:DiscussionList>
        <list:DiscussionListDetails>
         <list:DiscussionCreationDateFrom>2015-02-10</list:DiscussionCreationDateFrom>
         <list:DiscussionCreationDateTo>2015-02-10</list:DiscussionCreationDateTo>
        </list:DiscussionListDetails>
       </list:DiscussionList>
      </list:TransactionData>
     </list:TransactionContentDetails>
    </list:DiscussionTransactionBody>
   </list:Transaction>
  </ser:getDiscussionList>
 </soapenv:Body>
</soapenv:Envelope>

我想做的是使用 Zeep 复制这个原始查询。我该怎么做呢?
谢谢

最佳答案

我找到了一个 tutorial here,让我走上了正轨。这是我的代码:

from zeep import Client, Settings

#Creation of headerArr is excluded as it's not relevant to the xml produced
headerArr = {}
settings = Settings(strict=False, xml_huge_tree=True,extra_http_headers=headerArr)
client = Client('DiscussionCorrespondence/wsdls/DiscussionCorrespondence.wsdl',
    settings=settings)
requestData = {
    'Transaction': {
        'DiscussionTransactionBody': {
            'TransactionContentDetails': {
                'TransactionCode':'Get Discussion List',
                'TransactionData': {
                    'DiscussionList': {
                        'DiscussionListDetails': {
                                'DiscussionCreationDateFrom':'2015-02-10',
                                'DiscussionCreationDateTo':'2015-02-10',
                        },
                    },
                },
            },
        },
    },
}
res = client.service.getDiscussionList(**requestData)

发送的美化 XML 请求(来自调试日志)是:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
 <soap-env:Body>
  <ns0:getDiscussionList xmlns:ns0="http://www.iponz.govt.nz/services">
   <ns1:Transaction xmlns:ns1="http://www.iponz.govt.nz/XMLSchema/Discussion/List">
    <ns1:DiscussionTransactionBody>
     <ns1:TransactionContentDetails>
      <ns1:TransactionCode>Get Discussion List</ns1:TransactionCode>
      <ns1:TransactionData>
       <ns1:DiscussionList>
        <ns1:DiscussionListDetails>
         <ns1:DiscussionCreationDateFrom>2015-02-10</ns1:DiscussionCreationDateFrom>
         <ns1:DiscussionCreationDateTo>2015-02-10</ns1:DiscussionCreationDateTo>
        </ns1:DiscussionListDetails>
       </ns1:DiscussionList>
      </ns1:TransactionData>
     </ns1:TransactionContentDetails>
    </ns1:DiscussionTransactionBody>
   </ns1:Transaction>
  </ns0:getDiscussionList>
 </soap-env:Body>
</soap-env:Envelope>

此 XML 与问题中的 XML 不同,但在功能上应该相同。

关于python - 如何使用 Zeep 准备 SOAP 请求?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53778836/

10-15 08:53