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

Matt Goodall matt at pollenation.net
Mon Nov 14 09:10:31 MST 2005


Remi Cool wrote:
> 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.

The "self.putChild('RPC2', myXMLRPC(self.service))" line in the server
code makes your XMLRPC resource available as the "RPC2" child of the
root resource. That gives a full URL path to the XMLRPC resource of "/PRC2"

Your client code is not using the correct URL, so it's not requesting
the XMLRPC resource. The creation of the Proxy instance should be:

  proxy = Proxy('http://localhost:7080/RPC2')

Hope this helps.

- Matt

> 
> -- 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()
> 
> 
> 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

-- 
     __
    /  \__     Matt Goodall, Pollenation Internet Ltd
    \__/  \    w: http://www.pollenation.net
  __/  \__/    e: matt at pollenation.net
 /  \__/  \    t: +44 (0)113 2252500
 \__/  \__/
 /  \          Any views expressed are my own and do not necessarily
 \__/          reflect the views of my employer.



More information about the Twisted-web mailing list