mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 585 forks source link

How to override/except: zeep.transports: HTTP Response from https://enforce.symantec.com:443/ProtectManager/services/v2011/incidents (status: 500): #1098

Open don1m opened 4 years ago

don1m commented 4 years ago

help/support

data is encoded into db in XML format by another vendor application. occasionally a special character may be encoded in xml which causes abend/failure. One of the XML fields has a special character in it (white space character (0x15)) (international company)

python 3.6.5 zeep-3.4.0.dist

Question 1. can not seem to catch this error with current try/exception process. What is the correct way to catch this error?

zeep.transports: HTTP Post to https://host1.gooddomain.net:443/ProtectManager/services/v2011/incidents: <?xml version='1.0' encoding='utf-8'?>_

python code: try: myresults=(client.service.incidentDetail(**myrequest)) except Fault as exc: detail_decoded = client.wsdl.types.deserialize(exc.detail[0]) print(detail_decoded) print(type(detail_decoded))

Question 2. on the statement myresults=(client.service.incidentDetail(**myrequest)) the abend issues is the xml having the special character which generates the below error:

[com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x15) in text to output (in xml 1.1, could output as a character entity)]</S:Fault></S:Body></S:Envelope>

Is there way to override the handling the error: -- either allow special characters in the XML stream -- have them stripped out during the request statement --catch the 500 status error above so the record can be skipped

Full error: generated

zeep.transports: HTTP Post to https://enforce.symantec.com:443/ProtectManager/services/v2011/incidents: <?xml version='1.0' encoding='utf-8'?>

incidentDetailurn:uuid:913fba40-3a8a-48fd-b053-083b61b71c50https://enforce.symantec.com:443/ProtectManager/services/v2011/incidents01531903truefalse Warning (from warnings module): File "D:\apps\python36\lib\site-packages\urllib3\connectionpool.py", line 1004 InsecureRequestWarning, InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings zeep.transports: HTTP Response from https://enforce.symantec.com:443/ProtectManager/services/v2011/incidents (status: 500): S:Serverjavax.xml.bind.MarshalException - with linked exception: [com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x15) in text to output (in xml 1.1, could output as a character entity)] Traceback (most recent call last): File "D:\Apps\Plugins\DLP-api-test2-qa.py", line 81, in myresults=(client.service.incidentDetail(**myrequest)) File "D:\apps\python36\lib\site-packages\zeep\proxy.py", line 45, in __call__ kwargs, File "D:\apps\python36\lib\site-packages\zeep\wsdl\bindings\soap.py", line 130, in send return self.process_reply(client, operation_obj, response) File "D:\apps\python36\lib\site-packages\zeep\wsdl\bindings\soap.py", line 195, in process_reply return self.process_error(doc, operation) File "D:\apps\python36\lib\site-packages\zeep\wsdl\bindings\soap.py", line 299, in process_error detail=fault_node.find("detail"), zeep.exceptions.Fault: javax.xml.bind.MarshalException - with linked exception: [com.ctc.wstx.exc.WstxIOException: Invalid white space character (0x15) in text to output (in xml 1.1, could output as a character entity)]
da1910 commented 4 years ago

It looks as though this is an error in the server rather than on Zeep's end, that will be why you cannot catch it to debug.

A low effort fix if the existence of 0x15 whitespace isn't avoidable would be to replace it with spaces in the request. You can do that using a Plugin as described in the link above. Just define the egress() method to replace 0x15 with a space.