2013-07-22 48 views

回答

1

suds.WebFault has具有故障信息的故障字段。

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

你可以有你的程序從WebFault此類分析服務器自定義異常,併爲每一個特定的服務器異常的新的異常類(ES),再搭上suds.WebFault例外,讀取服務器異常的詳細信息,並提高您的自定義異常。

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)