Elliot Hughes
Elliot Hughes

Reputation: 1021

Make zeep use default namespace instead of named namespace in some cases

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?

Upvotes: 2

Views: 1340

Answers (1)

Elliot Hughes
Elliot Hughes

Reputation: 1021

You can achieve this with

client.set_ns_prefix(None, namespace_name)

Upvotes: 2

Related Questions