python zeep:将未转义的xml作为内容发送 [英] python zeep: send un-escaped xml as content

查看:293
本文介绍了python zeep:将未转义的xml作为内容发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我要执行的操作几乎类似于zeep repo中的 github问题 ---但可惜的是目前还没有任何回应.我研究了肥皂泡沫并安装并尝试了-甚至没有使发送参数正常工作,并认为zeep似乎可以更好地维护?

I think what I am trying to do is pretty much like github issue in zeep repo --- but sadly there is no response to this issue yet. I researched suds and installed and tried -- did not even get sending parameter to work and thought zeep seems better maintained?

当然,我不是在谈论

Edit 1: For sure I am not talking about this

推荐答案

您可以使用插件将xml编辑为纯字符串.我使用此插件来保留字符<"和CDATA元素中的>".

You can use a Plugin for editing the xml as a plain string. I used this plugin for keeping the characters '<' and '>' in a CDATA element.

from xml import etree
from zeep import Plugin

class my_plugin(Plugin):

    def egress(self, envelope, http_headers, operation, binding_options):
        xml_string = etree.ElementTree.tostring(envelope)
        xml_string = xml_string.replace("&lt;", "<")
        xml_string = xml_string.replace("&gt;", ">")
        parser = etree.ElementTree.XMLParser(strip_cdata=False)
        new_envelope = etree.ElementTree.XML(xml_string, parser=parser)
        return new_envelope, http_headers

然后只需将插件导入客户端:

Then just import the plugin on the client:

client = Client(wsdl='url', transport=transport, plugins=[my_plugin()])

看一下文档: http://docs.python- zeep.org/en/master/plugins.html

这篇关于python zeep:将未转义的xml作为内容发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆