I am getting the following error on the client side when I pass invalid XML characters to a Python SimpleXMLRPCServer:
Fault: <Fault 1: "<class 'xml.parsers.expat.ExpatError'>:not well-formed (invalid token): line 6, column 15">
Why? Do I have to change the SimpleXMLRPCServer library code to fix this?
Here is my XML-RPC server code:
from SimpleXMLRPCServer import SimpleXMLRPCServer
import logging
logging.basicConfig(level=logging.DEBUG)
def tt(text):
return "cool"
server = SimpleXMLRPCServer(("0.0.0.0", 9000))
server.register_introspection_functions()
server.register_function(tt)
# Run the server's main loop
server.serve_forever()
Here is my XML-RPC client code:
s = xmlrpclib.ServerProxy('http://localhost:9000')
s.tt(unichr(0x8))
On the server side, I don't get ANY error or traceback:
liXXXXXX.members.linode.com - - [06/Dec/2010 23:19:40] "POST /RPC2 HTTP/1.0" 200 -
Why no error on the server side? How do I diagnose what is going on?
And I get the following traceback on the client side:
/usr/lib/python2.6/xmlrpclib.pyc in __call__(self, *args)
1197 return _Method(self.__send, "%s.%s" % (self.__name, name))
1198 def __call__(self, *args):
-> 1199 return self.__send(self.__name, args)
1200
1201 ##
/usr/lib/python2.6/xmlrpclib.pyc in __request(self, methodname, params)
1487 self.__handler,
1488 request,
-> 1489 verbose=self.__verbose
1490 )
1491
/usr/lib/python2.6/xmlrpclib.pyc in request(self, host, handler, request_body, verbose)
1251 sock = None
1252
-> 1253 return self._parse_response(h.getfile(), sock)
1254
1255 ##
/usr/lib/python2.6/xmlrpclib.pyc in _parse_response(self, file, sock)
1390 p.close()
1391
-> 1392 return u.close()
1393
1394 ##
/usr/lib/python2.6/xmlrpclib.pyc in close(self)
836 raise ResponseError()
837 if self._type == "fault":
--> 838 raise Fault(**self._stack[0])
839 return tuple(self._stack)
840
Fault: <Fault 1: "<class 'xml.parsers.expat.ExpatError'>:not well-formed (invalid token): line 6, column 15">
How do I get sane server-side processing if the input contains invalid XML? Can I clean up this data server side? How?