Remi,
Your client code specifies the wrong URL. Just change
Proxy('http://localhost:7080') to Proxy('http://localhost:7080/RPC2'), and
you'll receive the echo response you are expecting.
Also, since you are using Twisted 2.1, I'd suggest abandoning the use of
components.Interface, and use zope.interface.Interface directly. See the
revised interfaces and adapters documentation on the web site for examples
of using zope.interface.Interface.
Hope this helps,
L. Daniel Burr
On Mon, 14 Nov 2005 09:35:46 -0600, Remi Cool <[EMAIL PROTECTED]>
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.
-- 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
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web