Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

python - Can you use Async Zeep to call a SOAP service behind Basic Auth?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...