Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

allow_none in twisted XML-RPC server

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">
like image 361
gruszczy Avatar asked Sep 21 '10 11:09

gruszczy


People also ask

How do I enable Allow_none on XML-RPC?

In your server class, add allow_none=True to your SimpleXMLRPCServer instantiation. The allow_none and encoding parameters are passed on to xmlrpc. client and control the XML-RPC responses that will be returned from the server.

Which are the parts of XML-RPC?

XML-RPC consists of three relatively small parts: XML-RPC data model : A set of types for use in passing parameters, return values, and faults (error messages). XML-RPC request structures : An HTTP POST request containing method and parameter information.

What is XML-RPC server?

XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a transport. With it, a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data.

How request is sent in XML-RPC?

XML-RPC requests are a combination of XML content and HTTP headers. The XML content uses the data typing structure to pass parameters and contains additional information identifying which procedure is being called, while the HTTP headers provide a wrapper for passing the request over the Web.


1 Answers

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)
like image 128
Jean-Paul Calderone Avatar answered Sep 27 '22 16:09

Jean-Paul Calderone