[Twisted-Python] Weird problem with XMLRPC -> ('405', 'Method Not Allowed')

Remi Cool mailinglists at smartology.nl
Fri Nov 4 05:49:01 EST 2005


Hello,

I've run into a problem with my twisted xmlrpc test server (using
twisted version 2.01 or 2.1).

Every time the client calls the echo function a '405 Method Not Allowed
is returned'.

One other thing is that pressing CTRL-C when the server is running,
results in the RuntimeError: can't stop reactor that isn't running.

Any ideas?

Here's the 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_rebuild(self, modname):
        """Rebuild the given module"""
        self.service.rebuild(modname)
        return true
   
    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()
##         user = request.getUser()
##         pwd = request.getPassword()
##         if (user and password):
        return resource.Resource.render(self, request)
##         else:
##             request.setResponseCode(401)
##             return '<html><body><h3>Must be
authenticated</h3></body></html>'

    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()
   
    try:
        try:
            print 'Running... '
            reactor.run()
        except KeyboardInterrupt:
            print 'CTRL-C received, shutting down server.'
        except Exception, e:
            print 'Problem with running server.'
    finally:
        reactor.stop()
        serviceCollection.stopService()

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-Python mailing list