Within my application, I need to access an internal (corporate) Soap API. For this access I have used Zeep so far. But now the access has to go through a proxy and the actual address of the API has to be converted to a virtual address of the proxy.
Creating the Zeep client also works correctly and I can access the WSDL files. However, the problem occurs when calling the respective service, because Zeep takes the corresponding URL from the WSDL file and this does not match the virtual address of the proxy.
I'll try to illustrate the problem below with my concrete code:
Assuming the address of the SOAP API is https://original-soap/wsdl?service=<service_name>
.
In the proxy there is a mapping from https://origial-soap
to http://virtual-soap
.
So the address Zeep should use then is http://virtual-soap/wsdl?service=<service_name>
.
I initialize my Zeep client as follows:
from requests.auth import HTTPBasicAuth
from requests import Session
from zeep import Client
from zeep.transports import Transport
from zeep.helpers import serialize_object
session = Session()
session.proxies = {
'http': 'http://<proxy_host>:<proxy_port>',
'https': 'http://<proxy_host>:<proxy_port>',
}
proxy_header = {
"Proxy-Authorization": "Bearer <proxy_access_token>"
}
session.headers.update(proxy_header)
session.verify = False
session.auth = HTTPBasicAuth(<soap_user>, <soap_password>)
transport = Transport(session=session)
client = Client(wsdl='http://virtual-saop/wsdl?service=<service_name>', transport=transport)
print('CLIENT INITIALIZED') # <-- This print command is executed
soap_result = client.service['<service_function_name>'](<function parameters>) # <-- Connectivity errors occur here
So my question is how I can also change the URL that Zeep uses when calling the service so that the virtual address is used here as well.
Thanks for any help in advance!
Thanks to @Bogdan, I solved the problem using the following code for the service initialization:
service = client.create_service(
client.service._binding.name, client.service._binding_options['address'].replace('https://original-soap:443', 'http://virtual-soap:80', 1)
)