gpt4 book ai didi

python - 如何使用 Zeep 准备 SOAP 请求?

转载 作者:太空宇宙 更新时间:2023-11-04 00:07:03 27 4
gpt4 key购买 nike

我正在尝试使用此处发布的特别神秘的 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 与问题中的不完全相同,但在功能上应该相同。

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com