title: Non-valid Unicode/XML with Python SimpleXMLRPCServer?
body: <p>I am getting the following error on the client side when I pass invalid XML characters to a Python SimpleXMLRPCServer:</p>
  
  <pre><code>Fault: &lt;Fault 1: "&lt;class 'xml.parsers.expat.ExpatError'&gt;:not well-formed (invalid token): line 6, column 15"&gt;
  </code></pre>
  
  <p>Why? Do I have to change the SimpleXMLRPCServer library code to fix this?</p>
  
  <p>Here is my XML-RPC server code:</p>
  
  <pre><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()
  </code></pre>
  
  <p>Here is my XML-RPC client code:</p>
  
  <pre><code>s = xmlrpclib.ServerProxy('http://localhost:9000')
  s.tt(unichr(0x8))
  </code></pre>
  
  <p>On the server side, I don't get ANY error or traceback:</p>
  
  <pre><code>liXXXXXX.members.linode.com - - [06/Dec/2010 23:19:40] "POST /RPC2 HTTP/1.0" 200 -
  </code></pre>
  
  <p>Why no error on the server side? How do I diagnose what is going on?</p>
  
  <p>And I get the following traceback on the client side:</p>
  
  <pre><code>/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):
  -&gt; 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,
  -&gt; 1489             verbose=self.__verbose
     1490             )
     1491 
  
  /usr/lib/python2.6/xmlrpclib.pyc in request(self, host, handler, request_body, verbose)
     1251             sock = None
     1252 
  -&gt; 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 
  -&gt; 1392         return u.close()
     1393 
     1394 ##
  
  
  /usr/lib/python2.6/xmlrpclib.pyc in close(self)
      836             raise ResponseError()
      837         if self._type == "fault":
  --&gt; 838             raise Fault(**self._stack[0])
      839         return tuple(self._stack)
      840 
  
  Fault: &lt;Fault 1: "&lt;class 'xml.parsers.expat.ExpatError'&gt;:not well-formed (invalid token): line 6, column 15"&gt;
  </code></pre>
  
  <p>How do I get sane server-side processing if the input contains invalid XML?
  Can I clean up this data server side? How?</p>