扭曲的 XML-RPC 服务器中的allow_none

发布于 2024-09-24 22:30:31 字数 1771 浏览 4 评论 0原文

我正在使用twisted构建xml rpc服务,我想使用None,就像它可以在标准python库中完成一样。如何将allow_none传递给扭曲版本的xmlrpc服务器?

编辑

In [28]: sock = rpc.ServerProxy('http://localhost:7080',allow_none=True)

In [29]: sock
Out[29]: <ServerProxy for localhost:7080/RPC2>

In [30]: sock.list_reports()
Out[30]: ['example']

In [31]: sock.run_report('example')
---------------------------------------------------------------------------
Fault                                     Traceback (most recent call last)

reports/<ipython console> in <module>()

/usr/lib/python2.6/xmlrpclib.pyc in __call__(self, *args)
   1197         return _Method(self.__send, "%s.%s" % (self.__name, name))
   1198     def __call__(self, *args):
-> 1199         return self.__send(self.__name, args)
   1200 
   1201 ##


/usr/lib/python2.6/xmlrpclib.pyc in __request(self, methodname, params)
   1487             self.__handler,
   1488             request,
-> 1489             verbose=self.__verbose
   1490             )
   1491 

/usr/lib/python2.6/xmlrpclib.pyc in request(self, host, handler, request_body, verbose)
   1251             sock = None
   1252 
-> 1253         return self._parse_response(h.getfile(), sock)
   1254 
   1255     ##


/usr/lib/python2.6/xmlrpclib.pyc in _parse_response(self, file, sock)
   1390         p.close()
   1391 
-> 1392         return u.close()
   1393 
   1394 ##


/usr/lib/python2.6/xmlrpclib.pyc in close(self)
    836             raise ResponseError()
    837         if self._type == "fault":
--> 838             raise Fault(**self._stack[0])
    839         return tuple(self._stack)
    840 

Fault: <Fault 8002: "Can't serialize output: cannot marshal None unless allow_none is enabled">

I am building xml rpc service using twisted and I would like to use None just as it can be done in standard python lib. How can I pass allow_none to the twisted version of xmlrpc server?

EDIT

In [28]: sock = rpc.ServerProxy('http://localhost:7080',allow_none=True)

In [29]: sock
Out[29]: <ServerProxy for localhost:7080/RPC2>

In [30]: sock.list_reports()
Out[30]: ['example']

In [31]: sock.run_report('example')
---------------------------------------------------------------------------
Fault                                     Traceback (most recent call last)

reports/<ipython console> in <module>()

/usr/lib/python2.6/xmlrpclib.pyc in __call__(self, *args)
   1197         return _Method(self.__send, "%s.%s" % (self.__name, name))
   1198     def __call__(self, *args):
-> 1199         return self.__send(self.__name, args)
   1200 
   1201 ##


/usr/lib/python2.6/xmlrpclib.pyc in __request(self, methodname, params)
   1487             self.__handler,
   1488             request,
-> 1489             verbose=self.__verbose
   1490             )
   1491 

/usr/lib/python2.6/xmlrpclib.pyc in request(self, host, handler, request_body, verbose)
   1251             sock = None
   1252 
-> 1253         return self._parse_response(h.getfile(), sock)
   1254 
   1255     ##


/usr/lib/python2.6/xmlrpclib.pyc in _parse_response(self, file, sock)
   1390         p.close()
   1391 
-> 1392         return u.close()
   1393 
   1394 ##


/usr/lib/python2.6/xmlrpclib.pyc in close(self)
    836             raise ResponseError()
    837         if self._type == "fault":
--> 838             raise Fault(**self._stack[0])
    839         return tuple(self._stack)
    840 

Fault: <Fault 8002: "Can't serialize output: cannot marshal None unless allow_none is enabled">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-10-01 22:30:31

XMLRPC 接受 allowNone 作为其初始值设定项的参数。因此,如果您想支持 None,请在实例化资源时传递 True

from twisted.web.xmlrpc import XMLRPC
resource = XMLRPC(allowNone=True)

XMLRPC accepts allowNone as an argument to its initializer. So, pass True when instantiating your resources if you want to support None.

from twisted.web.xmlrpc import XMLRPC
resource = XMLRPC(allowNone=True)
阳光①夏 2024-10-01 22:30:31

我认为它应该在客户端指定...

当您从 xmlrpc 客户端创建代理时 - 您可以为 python xmlrpclib 模块传递关键字参数allow_none = True,如下所示...

In [184]: import xmlrpclib as rpc

In [185]: sock = rpc.ServerProxy('http://localhost/xmlrpc/object',allow_none=True)

编辑:

from twisted.web.xmlrpc import Proxy
proxy = Proxy('http://localhost/xmlrpc', allowNone=True)

I think it should be specified on client side...

when you create the proxy from your xmlrpc client - you may pass the keyword argument allow_none = True for python xmlrpclib module like below...

In [184]: import xmlrpclib as rpc

In [185]: sock = rpc.ServerProxy('http://localhost/xmlrpc/object',allow_none=True)

EDIT:

from twisted.web.xmlrpc import Proxy
proxy = Proxy('http://localhost/xmlrpc', allowNone=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文