Reputation: 44345
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.)?
Upvotes: 0
Views: 1384
Reputation: 1122232
You are looking at the representation of the Fault
object; the string message itself is contained in the .faultString
attribute:
print fault.faultString
The __repr__
of the Fault class otherwise represents that value using repr()
; you cannot get around that without changing the xmlrpclib.Fault
class itself (by replacing it's __repr__
method or adding a __str__
method to it).
You could monkey patch that into the class:
from xmlrpclib import Fault
def fault_repr(self):
return "<Fault %s: %s>" % (self.faultCode, self.faultString)
Fault.__repr__ = fault_repr
Upvotes: 1