服务器代码(基于 Python 库参考):
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ()
server = SimpleXMLRPCServer(("127.0.0.1", 8000),
requestHandler=RequestHandler)
server.register_introspection_functions()
l = list()
def say_hi():
return 'hi !'
def append(event):
l.append(event)
server.register_function(say_hi)
server.register_function(append)
server.serve_forever()
客户端(解释器从另一个终端窗口启动):
>>> from xmlrpc.client import ServerProxy
>>> s = ServerProxy('http://127.0.0.1', allow_none=True)
>>> s.say_hi()
'hi !'
>>> s.append(1)
Traceback (most recent call last):
...
xmlrpc.client.Fault(Fault 1: "<class 'TypeError'>:cannot
marshal None unless allow_none is enabled")
我该如何解决?我是否不正确地使用 xmlrpc?