renzop
renzop

Reputation: 1316

How to create an async zeep client with wsdl file?

I have code that uses zeep to create a soap client. My server does not return the wsdl file but i have it locally.

The sycronous version works looks like this:

import uuid
from os import path
import structlog
import zeep

logger = structlog.get_logger(__name__)



class SyncClient(object):
    def __init__(self, ip_address: str):
        self.ip_address = ip_address
        self.port = 8080
        self.soap_client = None
        self.corrupt_timeseries_files = []
        self.id = uuid.uuid4()

    def connect_soap_client(self):
        this_files_dir = path.dirname(path.realpath(__file__))
        wsdl = 'file://{}'.format(path.join(this_files_dir, 'SOAPInterface.wsdl'))

        transport = zeep.Transport(timeout=5, operation_timeout=3)

        client = zeep.Client(wsdl, transport=transport)
        location = "http://{}:{}".format(self.ip_address, str(self.port))

        self.soap_client = client.create_service("{urn:webservices}SOAPInterface", location)

Then the asyc Client looks like this:

class AsyncClient(object):
    def __init__(self, ip_address: str):
        self.ip_address = ip_address
        self.port = 8080
        self.soap_client: zeep.client.Client = None
        self.corrupt_timeseries_files = []
        self.id = uuid.uuid4()

    def connect_soap_client(self):
        this_files_dir = path.dirname(path.realpath(__file__))
        wsdl = 'file://{}'.format(path.join(this_files_dir, 'SOAPInterface.wsdl'))

        transport = zeep.transports.AsyncTransport(timeout=5, wsdl_client=wsdl, operation_timeout=3)

        client = zeep.AsyncClient(wsdl, transport=transport)
        location = "http://{}:{}".format(self.ip_address, str(self.port))

        self.soap_client = client.create_service("{urn:webservices}SOAPInterface", location)

I have seen that the documentation of zeep states that the file loading is syncronous. But I don't get how I could create a async client when I have a local file...

Error message when i run my code in tests:

httpx.UnsupportedProtocol: Unsupported URL protocol 'file'

Upvotes: 5

Views: 3120

Answers (1)

lxop
lxop

Reputation: 8625

After debugging my way through the zeep and httpx source, I have found that the solution is actually quite simple:

Don't specify file://{path}, just specify {path}. Then the WSDL loads fine.

Upvotes: 4

Related Questions