如何在 zeep python 的 SOAP 请求的单个标签下发送多个值
How to send multiple values under single tag of SOAP Request in zeep python
我需要这样发送请求:
<soap:Body>
<ver:Notification>
<!--Optional:-->
<ver:messages>
<!--Zero or more repetitions:-->
<ver:Check>
<ver:ID>324007</ver:ID>
<ver:BranchList>
<ver:Branch >
<ver:Area>
<ver:XAxis>21.23</ver:XAxis>
<ver:YAxis>-09.11</ver:YAxis>
</ver:Area>
</ver:Branch>
</ver:BranchList>
</ver:Check>
<ver:Check>
<ver:ID>002345</ver:ID>
<ver:BranchList>
<ver:Branch >
<ver:Area>
<ver:XAxis>23.334</ver:XAxis>
<ver:YAxis>-11.23</ver:YAxis>
</ver:Area>
</ver:Branch>
</ver:BranchList>
</ver:Check>
</ver:messages>
</ver:Notification>
</soap:Body>
我正在 python 中使用 Zeep 库准备请求。我从 'upstream_messages' 中的上游获取一些值并迭代它并创建 list_of_messages 如下所示:
list_of_messages = []
for i in upstream_messages:
list_of_messages .append(
{'Check': {'ID': i[0],
'BranchList':
{'Branch':
{
'Area': {'XAxis': i[4], 'YAxis': i[5]}
}
}
}
}
)
但是当我使用以下代码检查请求时:
request = client.create_message(client.service, 'Notification', messages=list_of_messages )
logger.info(etree.tostring(request, pretty_print=True))
然后只获取 ID=324007 的第一个 'check' 标签,如下所示:
<soap-env:Envelope xmlns:soap-env="some http url/soap/envelope/">\n
<soap-env:Body>\n
<ns0:Notification xmlns:ns0="some http url /Version_1.1_Release">\n
<ns0:messages>\n
<ns0:Check>\n
<ns0:ID>324007</ns0:ID>\n
<ns0:BranchList>\n
<ns0:Branch>\n
<ns0:Area>\n
<ns0:XAxis>21.23</ns0:XAxis>\n
<ns0:YAxis>-09.11</ns0:YAxis>\n
</ns0:Area>\n
</ns0:Branch>\n
</ns0:BranchList>\n
</ns0:Check>\n
</ns0:messages>\n
</ns0:Notification>\n
</soap-env:Body>\n
</soap-env:Envelope>
请指出我做错了什么。我尝试使用 messages=[list_of_messages]
制作 list_of_messages 的列表列表,但后来我得到的输出没有消息标签
您需要将 Checks 用作数组而不是 list_of_messages。参见 https://github.com/mvantellingen/python-zeep/issues/272。
以下代码应该有效:
list_of_messages = {'Check': []}
for i in upstream_messages:
list_of_messages['Check'].append(
{'ID': i[0],
'BranchList':
{'Branch':
{
'Area': {'XAxis': i[4], 'YAxis': i[5]}
}
}
}
)
我需要这样发送请求:
<soap:Body>
<ver:Notification>
<!--Optional:-->
<ver:messages>
<!--Zero or more repetitions:-->
<ver:Check>
<ver:ID>324007</ver:ID>
<ver:BranchList>
<ver:Branch >
<ver:Area>
<ver:XAxis>21.23</ver:XAxis>
<ver:YAxis>-09.11</ver:YAxis>
</ver:Area>
</ver:Branch>
</ver:BranchList>
</ver:Check>
<ver:Check>
<ver:ID>002345</ver:ID>
<ver:BranchList>
<ver:Branch >
<ver:Area>
<ver:XAxis>23.334</ver:XAxis>
<ver:YAxis>-11.23</ver:YAxis>
</ver:Area>
</ver:Branch>
</ver:BranchList>
</ver:Check>
</ver:messages>
</ver:Notification>
</soap:Body>
我正在 python 中使用 Zeep 库准备请求。我从 'upstream_messages' 中的上游获取一些值并迭代它并创建 list_of_messages 如下所示:
list_of_messages = []
for i in upstream_messages:
list_of_messages .append(
{'Check': {'ID': i[0],
'BranchList':
{'Branch':
{
'Area': {'XAxis': i[4], 'YAxis': i[5]}
}
}
}
}
)
但是当我使用以下代码检查请求时:
request = client.create_message(client.service, 'Notification', messages=list_of_messages )
logger.info(etree.tostring(request, pretty_print=True))
然后只获取 ID=324007 的第一个 'check' 标签,如下所示:
<soap-env:Envelope xmlns:soap-env="some http url/soap/envelope/">\n
<soap-env:Body>\n
<ns0:Notification xmlns:ns0="some http url /Version_1.1_Release">\n
<ns0:messages>\n
<ns0:Check>\n
<ns0:ID>324007</ns0:ID>\n
<ns0:BranchList>\n
<ns0:Branch>\n
<ns0:Area>\n
<ns0:XAxis>21.23</ns0:XAxis>\n
<ns0:YAxis>-09.11</ns0:YAxis>\n
</ns0:Area>\n
</ns0:Branch>\n
</ns0:BranchList>\n
</ns0:Check>\n
</ns0:messages>\n
</ns0:Notification>\n
</soap-env:Body>\n
</soap-env:Envelope>
请指出我做错了什么。我尝试使用 messages=[list_of_messages]
制作 list_of_messages 的列表列表,但后来我得到的输出没有消息标签
您需要将 Checks 用作数组而不是 list_of_messages。参见 https://github.com/mvantellingen/python-zeep/issues/272。
以下代码应该有效:
list_of_messages = {'Check': []}
for i in upstream_messages:
list_of_messages['Check'].append(
{'ID': i[0],
'BranchList':
{'Branch':
{
'Area': {'XAxis': i[4], 'YAxis': i[5]}
}
}
}
)