服务器(CherryPy 3.2.0):
import cherrypy
class XMLRPCServer(cherrypy._cptools.XMLRPCController):
def index(self):
return 'index'
index.exposed = True
if __name__ =='__main__':
cherrypy.config.update({
'server.thread_pool': 1,
'request.dispatch': cherrypy.dispatch.XMLRPCDispatcher,
'tools.xmlrpc.on': True,
'tools.xmlrpc.allow_none': 0,
})
cherrypy.quickstart(XMLRPCServer())
客户端(Python 2.7.1):
import xmlrpclib
svc = xmlrpclib.ServerProxy('http://127.0.0.1:8080')
r = svc.index()
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1312, in single_request
response.msg,
xmlrpclib.ProtocolError: <ProtocolError for 127.0.0.1:8080/RPC2: 404 Not Found>
你如何在 CherryPy 中启用 xml-rpc,我已经用谷歌搜索并阅读了文档,但仍然卡住了。