python zeep: send un-escaped xml as content

随声附和 提交于 2020-02-03 04:53:05

问题


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


回答1:


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.

class my_lugin(Plugin):

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

Then just import the plugin on the client:

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

Take a look at the docs: http://docs.python-zeep.org/en/master/plugins.html



来源:https://stackoverflow.com/questions/48655638/python-zeep-send-un-escaped-xml-as-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!