Reputation:

Sending an exception on the SimpleXMLRPCServer

I'm trying to raise an exception on the Server Side of an SimpleXMLRPCServer; however, all attempts get a "Fault 1" exception on the client side.

RPC_Server.AbortTest() File "C:\Python25\lib\xmlrpclib.py", line 1147, in call return self.__send(self.__name, args) File "C:\Python25\lib\xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "C:\Python25\lib\xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "C:\Python25\lib\xmlrpclib.py", line 1340, in _parse_response return u.close() File "C:\Python25\lib\xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: :Test Aborted by a RPC request">

Upvotes: 0

Views: 793

Answers (2)

Kevin Whitefoot
Kevin Whitefoot

Reputation: 442

If you raise an exception like this:

raise Exception('Help!')

in the server the message member of the exception you get in the client will be the same as executing str() on the original exception prefixed with the string representation of the type.

The result I get for the message member is:

<type 'exceptions.Exception'>:Help!

You could certainly parse this to get the information you need.

Upvotes: 0

Mr_Pink
Mr_Pink

Reputation: 109367

Yes, this is what happens when you raise an exception on the server side. Are you expecting the SimpleXMLRPCServer to return the exception to the client?

You can only use objects that can be marshalled through XML. This includes

  • boolean : The True and False constants
  • integers : Pass in directly
  • floating-point numbers : Pass in directly
  • strings : Pass in directly
  • arrays : Any Python sequence type containing conformable elements. Arrays are returned as lists
  • structures : A Python dictionary. Keys must be strings, values may be any conformable type. Objects of user-defined classes can be passed in; only their __dict__ attribute is transmitted.
  • dates : in seconds since the epoch (pass in an instance of the DateTime class) or a datetime.datetime instance.
  • binary data : pass in an instance of the Binary wrapper class

Upvotes: 1

Related Questions