Issue
I'm trying to turn a previously working synchronous usage of the Zeep library into the Async version of this. On a request to the WSDL, the transport will always return a 404.
The following is the sync implementation and is working as intended.
session = Session()
session.auth = HTTPBasicAuth(username, password)
transport = Transport(session=session)
return Client(config_url, transport=transport)
However, when I change this to an async implementation (using httpx) it will return a Transport Error. The only message in this transport error is 401
.
http_client = httpx.Client()
http_client.auth = (username, password)
http_client.verify = True
transport = AsyncTransport(session=http_client)
return AsyncClient(config_url, transport=transport)
Am I using async Zeep correctly? According to the docs it should work like this
Solution
Ok, Apparently the interface isn't exactly the same. To instantiate a AsyncClient for zeep with basic auth, you'll need to create a Sync and Async client.
This is because zeep fetches the WSDL in a synchronous manner, and then executes the requests asynchronously. This means that the wsdl_client
must be synchronous and the client
must be ansynchronous!
async_client = httpx.AsyncClient(
auth=(username, password),
verify=True
)
wsdl_client = httpx.Client(
auth=(username, password),
verify=True
)
transport = AsyncTransport(client=async_client, wsdl_client=wsdl_client)
return AsyncClient(config_url, transport=transport)
With this, we can now await all service requests as described in the docs.
Answered By - requinard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.