[Twisted-web] Can't get XMLRPC server working with Twisted 2.1

Remi Cool mailinglists at smartology.nl
Mon Nov 14 08:35:46 MST 2005


Hello Twisters,

I've looked in the documentation, searched the archives and the web, but
found no solution to the XMLRPC problem I'm having.

I've used the finger example code to create an XMLRPC server, but I keep
getting the 405 Method not allowed error. I'm probably overlooking
something very obvious, call me stupid, but I can't get it to work.
Below the code I'm using.

If someone has a clue ... please enlighten me.

-- Remi --

Server code:

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-

""""""
import sys

from twisted.application import internet, service
from twisted.internet import reactor, protocol, defer
from twisted.web import resource, server, static, xmlrpc
from twisted.python import components, rebuild
from zope.interface import Interface, implements


class myXMLRPC(xmlrpc.XMLRPC):
    """This class contains all root xmlrpc methods and the modules
subhandler."""
    def __init__(self, service):
        xmlrpc.XMLRPC.__init__(self)
        self.service = service
   
    def xmlrpc_echo(self, x):
        """Simple echo function"""
        return x
       
   
def catchError(err):
    return "Internal error in server"
   
   
class IowwService(components.Interface):
    """"""
    def rebuild(self, modname):
        """Rebuild classes in given module"""
       

class httpResource(resource.Resource):

    implements(resource.IResource)
   
    def __init__(self, service):
        resource.Resource.__init__(self)
        self.service = service
        self.putChild('RPC2', myXMLRPC(self.service))      

    def render(self, request):
        self._clientIP = request.getClientIP()
        return resource.Resource.render(self, request)

    def render_GET(self, request):
        """Process HTTP GET Requests."""
        return '<html><body><h3>Not Implemented</h3></body></html>'
       
    def getChild(self, path, request):
        """This method handles http calls"""
        return httpResource(self.service)

components.registerAdapter(httpResource, IowwService, resource.IResource)


class owwService(service.Service):
    """"""
    implements(IowwService)
   
    def rebuild(self, modname):
        """Rebuild classes in given module"""
        mod = sys.modules[modname]
        rebuild.rebuild(mod)

       
def main():
    """"""
    application = service.Application('OWW', uid=100, gid=100)
    s = owwService()
    serviceCollection = service.IServiceCollection(application)
    internet.TCPServer(7080,
server.Site(resource.IResource(s))).setServiceParent(serviceCollection)
    serviceCollection.startService() 
    reactor.run()

if __name__ == '__main__':
    main()


And the client code:

#!/usr/bin/env python

from twisted.web.xmlrpc import Proxy
from twisted.internet import reactor

def printValue(value):
    print repr(value)
    reactor.stop()

def printError(error):
    print 'error', error
    reactor.stop()

proxy = Proxy('http://localhost:7080')
proxy.callRemote('echo', 'hello world').addCallbacks(printValue, printError)
reactor.run()





More information about the Twisted-web mailing list