gpt4 book ai didi

python - 如何使用 wsdl 文件创建异步 zeep 客户端?

转载 作者:行者123 更新时间:2023-12-04 12:57:04 28 4
gpt4 key购买 nike

我有使用 zeep 创建肥皂客户端的代码。我的服务器没有返回 wsdl 文件,但我在本地有它。
同步版本的工作原理如下:

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)
然后 asyc 客户端看起来像这样:
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)
我已经看到 zeep 的文档指出文件加载是同步的。但是当我有本地文件时,我不知道如何创建异步客户端......
在测试中运行代码时出现错误消息:
httpx.UnsupportedProtocol:不支持的 URL 协议(protocol)"file"

最佳答案

在通过 zeep 和 httpx 源调试我的方式后,我发现解决方案实际上非常简单:
不指定 file://{path} , 只需指定 {path} .然后 WSDL 加载正常。

关于python - 如何使用 wsdl 文件创建异步 zeep 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65203285/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com