如何使用Python ElementTree、LXML或类似的库创建soap请求

2024-05-16 01:01:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用excel表中的数据创建xmlsoap请求。目前,我使用了mako模板,但它需要XML模板。如何创建命名空间如下的请求(这只是一个小示例,而不是完整的XML):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mes="http://www.orange.com/Webalc/Interfaces/ManageSupplierQuote/RequestForQuotation/v3/message">
   <soapenv:Header/>
   <soapenv:Body>
      <mes:CalculateSupplierQuote>
         <!--1 to 500 repetitions:-->
         <SupplierQuote>
            <local_circuittype>Existing circuit</local_circuittype>
            <local_businessOpportunity>Access to Orange Business Services Network</local_businessOpportunity>
            <local_accessType>Upgrade/downgrade of full path diversity</local_accessType>
            <!--Optional:-->
            <local_configurationSite>single</local_configurationSite>

通过使用lxml库,我可以取得一些进展,但是我被卡住了。下面是我创建的代码。在

^{pr2}$

Tags: to数据模板httplocalxmlexcelxmlns
1条回答
网友
1楼 · 发布于 2024-05-16 01:01:29

您错误地构造了信封元素。 的构造函数etree.元素接收要创建的xml元素的(完全限定)名称(即标记),在您的示例中是信封。在

将第一行改为:

envelope = etree.Element("{http://www.w3.org/1999/soapenv}Envelope")

相关问题 更多 >