I'm trying get error detail, when I'm calling soap service with zeep.
How parse zeep.exceptions.Fault.detail? It's return lxml.etree._Element.
I'm using this code:
try:
client = Client(wsdl=self.__wsdl)
response = client.service.CustomerInformation(CustomerInformationService=self.service, faultStyle='wsdl')
except Fault as error:
detail = error.detail
# parse detail here
Here is response XML:
<?xml version="1.0" ?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body >
<soap-env:Fault >
<faultcode>soap-env:Client</faultcode>
<faultstring>Client Error</faultstring>
<detail>
<ouaf:Fault xmlns:ouaf="urn:oracle:ouaf">
<ResponseStatus>F</ResponseStatus>
<ResponseCode>2013</ResponseCode>
<ResponseText>
Error while executing the request:
(Server Message)
Category: 90006
Number: 32200
Call Sequence:
Program Name: CustomerInformationService
Text: The personal account was not found: 9134211141
Description:
Table: null
Field: null
</ResponseText>
<ResponseData numParm="1" text="The personal account was not found: 9134211141" category="90006" number="32200" parm1="9134211141" />
</ouaf:Fault>
</detail>
</soap-env:Fault>
</soap-env:Body >
</soap-env:Envelope>
Diffinition of 'Fault' type from xml data exist in my wsdl.
I know this is an old question but looking for the answer got me here and now I also know how to do it.
The URL to wsdl in the example is made up as well as the credentials.
import zeep
url_to_wsdl = 'www.some_SOAP_site.com/soap?wsdl'
client = zeep.Client(url_to_wsdl)
credentials = {
'login' : 'my_login',
'pass' : 'my_pass'
}
my_query = "SELECT COLUMN1 FROM TABLE1"
try:
client.service.query(my_query)
except zeep.exceptions.Fault as fault:
parsed_fault_detail = client.wsdl.types.deserialize(fault.detail[0])
print(parsed_fault_detail)
Results in
{
'errorCode': 'INVALID_SESSION',
'errorMessage': 'Invalid session!'
}
Don't forget the [0]
after fault.detail
and try incrementing it to see if there are more error details.
You can use error.code
or error.message
to match with the error that you want to look for.
https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/exceptions.py#L53
If you can't see anything in error.detail
, consider sending a PR to the python-zeep project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.