Write a custom Zeep plugin
mainYou can create custom plugins to process or modify data during the SOAP lifecycle. Plugins can intercept data at two stages:
- ingress: Triggered after a response is received from the server but before it is processed by the client. The
envelopeis the full SOAP envelope. - egress: Triggered before a request is sent to the server. The
envelopecontains only the body of the SOAP message.
Both methods must return a tuple containing the envelope (an lxml element) and the http_headers.
from lxml import etree
from zeep import Plugin
class MyLoggingPlugin(Plugin):
def ingress(self, envelope, http_headers, operation):
# Process received response
print(etree.tostring(envelope, pretty_print=True))
return envelope, http_headers
def egress(self, envelope, http_headers, operation, binding_options):
# Process outgoing request
print(etree.tostring(envelope, pretty_print=True))
return envelope, http_headers