Question

The xmlrpclib of python is a convenient way to communicate to a different computer over the internet, providing direct access to classes, functions and more. In the case of an error on the server side, this error is reported to the client side as a fault, consisting of some text-message and some fault-code.

The question I have, is how one can control these attributes on the server side, i.e. how to explicitly set the faultString and the faultCode to be sent to the client. The documentation seems very sparse in these details, and any help is appreciated.

Thanks,

Alex

Was it helpful?

Solution

After some digging I found an answer. To 'throw' an fault in the xmlrpc server, one can do simply

import xmlrpclib

# some code
if not ok:
  # throw fault:
  raise xmlrpclib.Fault(11, "some message")

which raises a Fault with faultCode 11 and faultString "some messsage" on the client side. This can be overridden to implement own error classes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top