在某些情况下,使zeep使用默认名称空间而不是命名名称空间

2024-09-27 04:27:17 发布

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

我使用Zeep向供应商提供的soap1.1api发送请求,该API构建在WCF之上,但似乎有一些特定的特性。你知道吗

Zeep目前正在生成这样的XML

  <soap-env:Body>
    <ns0:GetDataServers xmlns:ns0="AIR.Services.DataSourceManagementService.Api">
      <ns0:request>
        <ns1:BusinessUnitSid xmlns:ns1="AIR.Services.Common.Api">1</ns1:BusinessUnitSid>
        <ns2:LicenseUid xmlns:ns2="AIR.Services.Common.Api">00000000-0000-0000-0000-000000000000</ns2:LicenseUid>
        <ns3:RequestUid xmlns:ns3="AIR.Services.Common.Api">00000000-0000-0000-0000-000000000000</ns3:RequestUid>
        <ns4:SqlInstanceSid xmlns:ns4="AIR.Services.Common.Api">1</ns4:SqlInstanceSid>
      </ns0:request>
    </ns0:GetDataServers>
  </soap-env:Body>

但是,这会被拒绝,并出现错误Error in line 1 position 74. Expecting element 'GetDataServersRequest' from namespace 'AIR.Services.DataSourceManagement.Api'.. Encountered 'Element' with name 'GetDataServersRequest', namespace ''.

但是如果我将ns0设为默认名称空间,它就可以工作了

<soap-env:Body>
    <GetDataServers xmlns="AIR.Services.DataSourceManagementService.Api">
      <request>
        <ns1:BusinessUnitSid xmlns:ns1="AIR.Services.Common.Api">1</ns1:BusinessUnitSid>
        <ns2:LicenseUid xmlns:ns2="AIR.Services.Common.Api">00000000-0000-0000-0000-000000000000</ns2:LicenseUid>
        <ns3:RequestUid xmlns:ns3="AIR.Services.Common.Api">00000000-0000-0000-0000-000000000000</ns3:RequestUid>
        <ns4:SqlInstanceSid xmlns:ns4="AIR.Services.Common.Api">1</ns4:SqlInstanceSid>
      </request>
    </GetDataServers>
  </soap-env:Body>

有没有办法让Zeep在这个位置使用一个普通的xmlns默认名称空间?你知道吗


Tags: envapirequestbodycommonairsoapxmlns

热门问题