-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZeepDebugPlugin.py
28 lines (22 loc) · 1.06 KB
/
ZeepDebugPlugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
"""
Zeep Debug Plugin
This class enables a Zeep object to output logs containing the received and sent SOAP requests
@author: Alfonso Sandoval
"""
import logging
from zeep import Plugin
from lxml import etree
class ZeepDebugPlugin( Plugin ):
def egress( self, envelope, http_headers, operation, binding_options ):
"""Output in console logs the sent SOAP request"""
# Format the request body as pretty printed XML
logging.basicConfig(level=logging.DEBUG)
xml = etree.tostring( envelope, pretty_print = True, encoding = 'unicode')
logging.debug( f'\nRequest\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}' )
def ingress( self, envelope, http_headers, operation ):
"""Output in console logs the received SOAP request"""
# Format the response body as pretty printed XML
logging.basicConfig(level=logging.DEBUG)
xml = etree.tostring( envelope, pretty_print = True, encoding = 'unicode')
logging.debug( f'\nResponse\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}' )