2

I'm using Zeep to send requests to a SOAP 1.1 API supplied by a vendor, the API is built on WCF but seems to have some specific peculiarities.

Zeep is currently generating XML like this

  <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>

However this is rejected with an error Error in line 1 position 74. Expecting element 'GetDataServersRequest' from namespace 'AIR.Services.DataSourceManagement.Api'.. Encountered 'Element' with name 'GetDataServersRequest', namespace ''.

But if I make ns0 the default namespace it works

<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>

Is there a way to make Zeep use a plain xmlns default namespace in this position?

Elliot Hughes
  • 967
  • 1
  • 9
  • 19
  • This is a duplicate of https://stackoverflow.com/questions/55812660/how-to-set-default-xmlns-with-zeep-in-python/56158276#56158276 but the answer hasn't been accepted yet. – Elliot Hughes May 15 '19 at 22:08

1 Answers1

2

You can achieve this with

client.set_ns_prefix(None, namespace_name)
Elliot Hughes
  • 967
  • 1
  • 9
  • 19