Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Service URL in Python Zeep

Tags:

python

soap

I want to use Python Zeep SOAP Client to make SOAP Calls to an Cisco CUCM. In the Cisco WSDL File is the Service definded:

<service name="AXLAPIService">
    <port binding="s0:AXLAPIBinding" name="AXLPort">
        <soap:address location="https://CCMSERVERNAME:8443/axl/"/>
    </port>
</service>

Now i want to change the "CCMSERVERNAME" to something real, like "192.168.250.10" without changing the WSDL.

But from the Docs i can't find anything to change that.

I found an Discussion here about changing the URL with "Client.set_address()" but this don't work anymore.

Can anybody give me an hint?

Edit: With mvt's help i got it, for anybody with the same problem, create the service with this command:

service = client.create_service("  {http://www.cisco.com/AXLAPIService/}AXLAPIBinding","https://192.168.250.10:8443/axl/")

Here an example from an working SOAP call:

phones = service.listPhone({'devicePoolName':'Default'},returnedTags={'name':'','model':''})

returns Devices in an list:

SEPFFFFFFFFFFAA Cisco 7841
SEPAAAABBBB2222 Cisco 7841
like image 749
eisbaer9 Avatar asked Feb 14 '17 21:02

eisbaer9


2 Answers

This should be possible via http://docs.python-zeep.org/en/master/client.html#creating-new-serviceproxy-objects

Cheers (author of zeep)

like image 139
mvantellingen Avatar answered Oct 17 '22 08:10

mvantellingen


For an endpoint on a internal server, not reachable over the internet, port-forwarded port 80 using ssh to localhost:8080 I made the following snippet, it copies the service binding and applies a translation to the binding address to create a new service.

def get_service(client, translation):
    if translation:
        service_binding = client.service._binding.name
        service_address = client.service._binding_options['address']
        return client.create_service(
            service_binding,
            service_address.replace(*translation, 1))
    else:
        return client.service

# ssh port forwarded internal.example.com:80 to localhost:8080

client = zeep.Client(wsdl="localhost:8080/endpoint?WSDL")

# client.service now points to the unreachable url internal.example.com/endpoint

service = get_service(client=client, translation=('internal.example.com', 'localhost:8080'))

# service now points to localhost:8080/endpoint
like image 5
Pelle Avatar answered Oct 17 '22 08:10

Pelle