为什么 xmlrpc 客户端无法将项目附加到可通过 xmlrpc 服务器程序访问的列表中?
服务器代码(基于 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 不当?
Server code (based on Python library reference):
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()
Client (interpreter started from another terminal window):
>>> 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")
How do I fix this? Am I using xmlrpc improperly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 XMLRPC 服务器正在引发错误,因为它无法封送
None
。您需要将allow_none=True
添加到服务器构造函数:Your XMLRPC server is raising a fault since it cannot marshal
None
. You need to addallow_none=True
to the server constructor: