@@ -594,9 +594,13 @@ def _log_request( self, request, donotlogbody=False, intent=None, action=None ):
594594 if rawtext .startswith ( '<?xml' ) or rawtext .startswith ( '<rdf' ):
595595 # assume XML
596596# print( f"is xml {rawtext[0:4]}" )
597- tree = ET .fromstring ( rawtext )
598- ET .indent (tree , space = " " )
599- rawtext = ET .tostring ( tree )
597+ try :
598+ body_bytes = request .body if isinstance (request .body , bytes ) else request .body .encode ('utf-8' )
599+ tree = ET .fromstring ( body_bytes )
600+ ET .indent (tree , space = " " )
601+ rawtext = ET .tostring ( tree , encoding = 'unicode' )
602+ except Exception :
603+ pass # keep rawtext as-is
600604 else :
601605# print( f"not xml {rawtext[0:4]}" )
602606 pass
@@ -658,9 +662,12 @@ def _log_response( self, response, action=None ):
658662 if rawtext .startswith ( '<?xml' ) or rawtext .startswith ( '<rdf' ):
659663 # assume XML
660664# print( f"is xml {rawtext[0:4]}" )
661- tree = ET .fromstring ( rawtext .encode () )
662- ET .indent (tree , space = " " )
663- rawtext = ET .tostring ( tree ).decode ()
665+ try :
666+ tree = ET .fromstring ( response .content )
667+ ET .indent (tree , space = " " )
668+ rawtext = ET .tostring ( tree , encoding = 'unicode' )
669+ except Exception :
670+ pass # keep rawtext as-is
664671 else :
665672# print( f"not xml {rawtext[0:4]}" )
666673 pass
0 commit comments