On the server side of a xmlrpc server in python I have the following line of code within a function overwriting SimpleXMLRPCServer._marshaled_dispatch:
response = xmlrpclib.dumps(
xmlrpclib.Fault(1, "some error\nnext line\n"),
encoding=self.encoding, allow_none=self.allow_none)
to create some custom error/fault message to be show on the client side. However, this code will show something like the following on the client side
xmlrpclib.Fault: <Fault 1: "some error\nnext line\n">
whereas I want to have something like
xmlrpclib.Fault: <Fault 1: "some error
next line
">
i.e. where the newline character is actually ‘used’ and not printed.
Any ideas I can accomplish this (per server side, i.e. modification of the line just shown above, and without using a third party package.)?
You are looking at the representation of the
Faultobject; the string message itself is contained in the.faultStringattribute:The
__repr__of the Fault class otherwise represents that value usingrepr(); you cannot get around that without changing thexmlrpclib.Faultclass itself (by replacing it’s__repr__method or adding a__str__method to it).You could monkey patch that into the class: