3

I want to use zeep to make some API calls. The expected output is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://cabapi-prod.service.dbrent.net/hal2_cabserver/">
  <soap:Body>
    <CABSERVER.listFreeBikes>
      <CommonParams>
        <UserData>
          <User>XXXXXXXXXXXXXX</User>
          <Password>XXXXXXXXXXXXXX</Password>
        </UserData>
        <LanguageUID>1</LanguageUID>
        <RequestTime>XXXXXXXXXXXXXX</RequestTime>
        <Version>2</Version>
      </CommonParams>
      <SearchPosition>
        <Longitude>XXXXXXXXXXXXXX</Longitude>
        <Latitude>XXXXXXXXXXXXXX</Latitude>
      </SearchPosition>
      <maxResults>100</maxResults>
      <searchRadius>844</searchRadius>
      <CustomerData>
        <Phone>XXXXXXXXXXXXXX</Phone>
        <Password>XXXXXXXXXXXXXX</Password>
        <PhoneUserEdited>false</PhoneUserEdited>
      </CustomerData>
    </CABSERVER.listFreeBikes>
  </soap:Body>
</soap:Envelope>

However, I am only able to get:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:CABSERVER.listFreeBikes xmlns:ns0="https://xml.dbcarsharing-buchung.de/hal2_cabserver/">
      <CommonParams>
        <UserData>
          <User>XXXXXXXXXXXXXX</User>
          <Password>XXXXXXXXXXXXXX</Password>
        </UserData>
        <LanguageUID>1</LanguageUID>
        <RequestTime>XXXXXXXXXXXXXX</RequestTime>
        <Version>2</Version>
      </CommonParams>
      <CustomerData>
        <Phone>XXXXXXXXXXXXXX</Phone>
        <Password>XXXXXXXXXXXXXX</Password>
        <PhoneUserEdited>false</PhoneUserEdited>
      </CustomerData>
      <SearchPosition>
        <Longitude>XXXXXXXXXXXXXX</Longitude>
        <Latitude>XXXXXXXXXXXXXX</Latitude>
      </SearchPosition>
      <maxResults>100</maxResults>
      <searchRadius>844</searchRadius>
    </ns0:CABSERVER.listFreeBikes>
  </soap-env:Body>
</soap-env:Envelope>

The server is not able to recognize my request correctly and I think it is because of the namespace. I did some research but did not find a way to set the default namespace (xmlns) to https://xml.dbcarsharing-buchung.de/hal2_cabserver/. Instead, it gets added as extra namespace.

This is my current code:

with client.settings(raw_response=True):
    ## Common Params related
    ### UserData related
    userNameType = client.get_type('ns0:Type_UserName')
    userPasswordType = client.get_type('ns0:Type_UserPassword')
    userName = userNameType('XXXXXXXXXXXXXX')
    userPassword = userPasswordType('XXXXXXXXXXXXXX')
    userDataType = client.get_type('ns0:Type_UserData')
    userData = userDataType(User = userName, Password = userPassword)


    current_time = time.localtime()
    current_time_str = time.strftime('%Y-%m-%dT%H:%M:%S.GMT+02:00', current_time)

    commonParamsType = client.get_type('ns0:Type_CommonParams')
    commonParams = commonParamsType(UserData = userData, LanguageUID = 1, RequestTime = current_time_str, Version = 2)

    ## CustomerData related
    customerPhoneType = client.get_type('ns0:Type_CustomerPhone')
    customerPhone = customerPhoneType('XXXXXXXXXXXXXX') # Get from config
    customerPasswordType = client.get_type('ns0:Type_CustomerPassword')
    customerPassword = customerPasswordType('XXXXXXXXXXXXXX') #Get from config
    customerDataType = client.get_type('ns0:Type_CustomerData')
    customerData = customerDataType(Phone = customerPhone, Password = customerPassword, PhoneUserEdited = False)

    ## SearchPosition related
    geoPositionType = client.get_type('ns0:Type_GeoPosition')
    geoPosition = geoPositionType(Longitude = XXXXXXXXXXXXXX, Latitude = XXXXXXXXXXXXXX)

    # DEBUG
    node = client.create_message(client.service, 'CABSERVER.listFreeBikes', CommonParams = commonParams, CustomerData = customerData, SearchPosition = geoPosition, maxResults = 100, searchRadius = 844)
    from lxml import etree as ET
    tree = ET.ElementTree(node)
    tree.write('test.xml', pretty_print=True)

What I tried so far:

client.set_ns_prefix('ns0', '')

However that does not solve my issue. I am running out of ideas. Anyone who can point me into the right direction?

The WSDL can be found here: https://xml.dbcarsharing-buchung.de/hal2_cabserver/definitions/HAL2_CABSERVER_3.wsdl

heyhey
  • 31
  • 1
  • 3

1 Answers1

5

You were close

client.set_ns_prefix('ns0', '')

Should read

client.set_ns_prefix(None, "https://xml.dbcarsharing-buchung.de/hal2_cabserver/")

Then the default namespace should be used.

Elliot Hughes
  • 967
  • 1
  • 9
  • 19