如何在Zeep插件中使用asyncio库
在将SOAP请求发送到服务器之前,我需要使用外部程序向其添加一些标签。 我已经写了插件到Zeep库:
class ZeepSignPlugin(Plugin):
def egress(self, envelope, http_headers, operation, binding_options):
tmp_filename = 'tmp_filename.xml'
tmp_signed_filename = 'tmp_signed_filename.xml'
et = etree.ElementTree(envelope)
et.write(tmp_filename, pretty_print=True)
proc = subprocess.Popen([
Config.exe_path,
'sign',
'-f' + tmp_filename,
'-o' + tmp_signed_filename,
'-v',
], stdout=subprocess.PIPE)
output = proc.stdout.read()
print(output.decode('CP866'))
newenvelope = etree.parse(tmp_signed_filename)
os.remove(tmp_filename)
os.remove(tmp_signed_filename)
return newenvelope, http_headers
我尝试过这样的代码:
loop = asyncio.get_running_loop()
proc = loop.subprocess_exec(
Config.exe_path,
'sign',
'-f' + tmp_filename,
'-o' + tmp_signed_filename,
'-v',
stdout=asyncio.subprocess.PIPE)
loop.run_until_complete(proc)
但返回错误:
RuntimeError:此事件循环已在运行
如何在Zeep插件中使用asyncio库?