Returning Fault instances in xmlrpc

Brian Quinlan brian at sweetapp.com
Sun May 5 02:12:21 EDT 2002


> But why aren't Fault objects returned when I explicitly return them
> from my functions? Shouldn't it either be illegal to return them or
> equivalent to raising them?

Both of these Python functions are legal but they have different
semantics:

def myfunc(): raise TypeError()
def myfunc(): return TypeError()

Do you consider that a design flaw? If not, why should it be a design
flaw with the xmlrpc library?

> The specification says nothing about exceptions -- only Fault objects.
> I'm just curious about how they interact with Python exceptions, and
> how you are supposed to use them in the standard xmlrpclib.

It sounds like you are writing a server. Are you using
SimpleXMLRPCServer or marshalling the data yourself?

If you are using SimpleXMLRPCServer, you can just raise exceptions like
normal and they will be converted into XML-RPC faults. Or you can raise
xmlrpclib.Fault objects.

The xmlrpclib client code raises xmlrpclib.Fault objects in response to
XML-RPC faults.

Cheers,
Brian






More information about the Python-list mailing list