@@ -615,9 +615,13 @@ def _log_request( self, request, donotlogbody=False, intent=None, action=None ):
615615 if rawtext .startswith ( '<?xml' ) or rawtext .startswith ( '<rdf' ):
616616 # assume XML
617617# print( f"is xml {rawtext[0:4]}" )
618- tree = ET .fromstring ( rawtext )
619- ET .indent (tree , space = " " )
620- rawtext = ET .tostring ( tree )
618+ try :
619+ body_bytes = request .body if isinstance (request .body , bytes ) else request .body .encode ('utf-8' )
620+ tree = ET .fromstring ( body_bytes )
621+ ET .indent (tree , space = " " )
622+ rawtext = ET .tostring ( tree , encoding = 'unicode' )
623+ except Exception :
624+ pass # keep rawtext as-is
621625 else :
622626# print( f"not xml {rawtext[0:4]}" )
623627 pass
@@ -681,9 +685,12 @@ def _log_response( self, response, action=None ):
681685 if rawtext .startswith ( '<?xml' ) or rawtext .startswith ( '<rdf' ):
682686 # assume XML
683687# print( f"is xml {rawtext[0:4]}" )
684- tree = ET .fromstring ( rawtext .encode () )
685- ET .indent (tree , space = " " )
686- rawtext = ET .tostring ( tree ).decode ()
688+ try :
689+ tree = ET .fromstring ( response .content )
690+ ET .indent (tree , space = " " )
691+ rawtext = ET .tostring ( tree , encoding = 'unicode' )
692+ except Exception :
693+ pass # keep rawtext as-is
687694 else :
688695# print( f"not xml {rawtext[0:4]}" )
689696 pass
0 commit comments