Change Service URL in Python Zeep

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

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

Cheers (author of zeep)

Tags:

Python

Soap