Twisted XML-RPC error
Question: I get an exception on both client and server side when I run the first example
at <http://buildbot.twistedmatrix.com/builds/sphinx-
html/291-15849/projects/web/howto/xmlrpc.html>. The server code I used is
below:

    
    
    from twisted.web import xmlrpc, server
    
    class Example(xmlrpc.XMLRPC):
        """An example object to be published."""
    
        def xmlrpc_echo(self, x):
            """
            Return all passed args.
            """
            return x
    
        def xmlrpc_add(self, a, b):
            """
            Return sum of arguments.
            """
            return a + b
    
        def xmlrpc_fault(self):
            """
            Raise a Fault indicating that the procedure should not be used.
            """
            raise xmlrpc.Fault(123, "The fault procedure is faulty.")
    
    if __name__ == '__main__':
        from twisted.internet import reactor
        r = Example()
        reactor.listenTCP(7080, server.Site(r))
        reactor.run()
    

Client side is below:

    
    
    import xmlrpclib
    
    s = xmlrpclib.Server('http://localhost:7080/')
    print s.echo('Hello world')
    

The server side exception is:

    
    
    Traceback (most recent call last):
      File "/usr/lib/python2.6/dist-packages/twisted/web/xmlrpc.py", line 150, in render_POST
        d.addCallback(self._cbRender, request, responseFailed)
      File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 260, in addCallback
        callbackKeywords=kw)
      File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 249, in addCallbacks
        self._runCallbacks()
      File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 441, in _runCallbacks
        self.result = callback(self.result, *args, **kw)
    --- <exception caught here> ---
      File "/usr/lib/python2.6/dist-packages/twisted/web/xmlrpc.py", line 170, in _cbRender
        allow_none=self.allowNone)
    exceptions.TypeError: dumps() got an unexpected keyword argument 'allow_none'
    

Client side exception is:

    
    
    Traceback (most recent call last):
      File "./client.py", line 6, in <module>
        print s.echo('Hello world')
      File "/usr/local/lib/python2.6/dist-packages/xmlrpclib-1.0.1-py2.6.egg/xmlrpclib.py", line 986, in __call__
        return self.__send(self.__name, args)
      File "/usr/local/lib/python2.6/dist-packages/xmlrpclib-1.0.1-py2.6.egg/xmlrpclib.py", line 1239, in __request
        verbose=self.__verbose
      File "/usr/local/lib/python2.6/dist-packages/xmlrpclib-1.0.1-py2.6.egg/xmlrpclib.py", line 1037, in request
        return self._parse_response(h.getfile(), sock)
      File "/usr/local/lib/python2.6/dist-packages/xmlrpclib-1.0.1-py2.6.egg/xmlrpclib.py", line 1136, in _parse_response
        p.close()
      File "/usr/local/lib/python2.6/dist-packages/xmlrpclib-1.0.1-py2.6.egg/xmlrpclib.py", line 508, in close
        self._parser.Parse("", 1) # end of data
    xml.parsers.expat.ExpatError: no element found: line 1, column 0
    


Answer: Looks like you have an old version of xmlrpclib?

What version of python are you using? Where is the xmlrpclib coming from that
your xmlrpc server is using, and what version is it?

    
    
    $ python -v
    >>> import xmlrpclib
    # /usr/lib/python2.6/xmlrpclib.pyc matches /usr/lib/python2.6/xmlrpclib.py
    >>> xmlrpclib.__version__
    '1.0.1'
    >>> xmlrpclib.dumps((None,), allow_none=True)
    '<params>\n<param>\n<value><nil/></value></param>\n</params>\n
    

i.e. this works for me. Perhaps you are somehow using an old version of
xmlrpclib?

