0

I have a java web service and python client using suds. My server raises custom exceptions which I would like to handle in the python script. Is it possible to catch them or it always will be caught as suds.WebFault exception?

user1107922
  • 610
  • 1
  • 12
  • 25

1 Answers1

1

suds.WebFault has fault field that has information about fault.

except suds.WebFault, e:
    print e.fault.faultstring
    print e.document

You can have your program to analyze server custom exception from WebFault and create new exception class(es) for every specific server exception then catch suds.WebFault exception, read server exception details and raise your custom exception.

class MyException(suds.WebFault):
    pass


def convertServerException(e):
    if e.fault.faultstring == 'exception1':
        return MyException()
        #...add more exception handling cases here

#...
try:
#...make a WebService call
except suds.WebFault, e:
    print e
    print e.fault
    raise convertServerException(e)
vvladymyrov
  • 5,715
  • 2
  • 32
  • 50