exceptions.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ''' Core exceptions raised by the ONVIF Client '''
  2. #from suds import WebFault, MethodNotFound, PortNotFound, \
  3. # ServiceNotFound, TypeNotFound, BuildError, \
  4. # SoapHeadersNotPermitted
  5. #TODO: Translate these errors into ONVIFError instances, mimicking the original 'suds' behaviour
  6. #from zeep.exceptions import XMLSyntaxError, XMLParseError, UnexpectedElementError, \
  7. # WsdlSyntaxError, TransportError, LookupError, NamespaceError, Fault, ValidationError, \
  8. # SignatureVerificationFailed, IncompleteMessage, IncompleteOperation
  9. # Error codes setting
  10. # Error unknown, e.g, HTTP errors
  11. ERR_ONVIF_UNKNOWN = 1
  12. # Protocol error returned by WebService,
  13. # e.g:DataEncodingUnknown, MissingAttr, InvalidArgs, ...
  14. ERR_ONVIF_PROTOCOL = 2
  15. # Error about WSDL instance
  16. ERR_ONVIF_WSDL = 3
  17. # Error about Build
  18. ERR_ONVIF_BUILD = 4
  19. class ONVIFError(Exception):
  20. def __init__(self, err):
  21. # if isinstance(err, (WebFault, SoapHeadersNotPermitted) if with_soap_exc else WebFault):
  22. # self.reason = err.fault.Reason.Text
  23. # self.fault = err.fault
  24. # self.code = ERR_ONVIF_PROTOCOL
  25. # elif isinstance(err, (ServiceNotFound, PortNotFound,
  26. # MethodNotFound, TypeNotFound)):
  27. # self.reason = str(err)
  28. # self.code = ERR_ONVIF_PROTOCOL
  29. # elif isinstance(err, BuildError):
  30. # self.reason = str(err)
  31. # self.code = ERR_ONVIF_BUILD
  32. # else:
  33. self.reason = 'Unknown error: ' + str(err)
  34. self.code = ERR_ONVIF_UNKNOWN
  35. def __str__(self):
  36. return self.reason