xmlrpclib and SimpleXMLRPCServer questions

Jeff McNeil jeff at jmcneil.net
Wed Sep 12 22:16:44 CEST 2007


Duh... you can pass allow_none=True to SimpleXMLRPCServer()....


On 9/12/07, Jeff McNeil <jeff at jmcneil.net> wrote:
> Have a look at the XMLRPC specification @ http://www.xmlrpc.com/spec.
> There is no representation of NULL/None, thus server refuses to
> Marshall the 'None' value.  Update your server methods to return a
> value other than None and that message will go away.
>
> The other option is to set 'allow_none' to True on the Marshaller
> object. Doing so will turn your 'None' return values into XML-RPC
> '<nil/>' entities.  The 'nil' type is defined as an XMLRPC extension
> (I'm not sure how widely adopted it is, though).  See
> http://ontosys.com/xml-rpc/extensions.php.  I'm not sure you can do
> that without inheriting from the dispatcher code and "rolling your
> own."
>
> I find it much easier to 'return True' and ignore the value.
>
> -Jeff
>
> On 9/12/07, xkenneth <xkenneth at gmail.com> wrote:
> > So i've been trying to set up a simple server and client through
> > XMLRPC in python.
> >
> > Here's my code:
> >
> > SERVER
> >
> > import SimpleXMLRPCServer
> >
> >
> > class DataServer:
> >     def __init__(self):
> >         pass
> >
> >     def test(self,test):
> >         self.this = test
> >
> >     def show(self):
> >         print self.this
> >
> > server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8005))
> > server.register_instance(DataServer())
> > server.serve_forever()
> >
> > CLIENT
> > import xmlrpclib
> > server = xmlrpclib.Server('http://localhost:8005')
> > server.test(5)
> > server.show()
> >
> >
> > Now, I'm getting the most odd callback from the client side:
> >
> > >>> server.show()
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> >   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> > lib/python2.4/xmlrpclib.py", line 1096, in __call__
> >     return self.__send(self.__name, args)
> >   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> > lib/python2.4/xmlrpclib.py", line 1383, in __request
> >     verbose=self.__verbose
> >   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> > lib/python2.4/xmlrpclib.py", line 1147, in request
> >     return self._parse_response(h.getfile(), sock)
> >   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> > lib/python2.4/xmlrpclib.py", line 1286, in _parse_response
> >     return u.close()
> >   File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/
> > lib/python2.4/xmlrpclib.py", line 744, in close
> >     raise Fault(**self._stack[0])
> > xmlrpclib.Fault: <Fault 1: 'exceptions.TypeError:cannot marshal None
> > unless allow_none is enabled'>
> >
> > What is causing this? The server recieves the data and seems to
> > respond properly regardless of this error, so by all means i can
> > always catch it, but that sounds stupid.
> >
> > Here I can verify the server process is indeed recieving the data
> > (calling the client with two different values):
> >
> > localhost - - [12/Sep/2007 14:35:18] "POST /RPC2 HTTP/1.0" 200 -
> > 5
> > localhost - - [12/Sep/2007 14:35:41] "POST /RPC2 HTTP/1.0" 200 -
> > 10
> >
> > Looking at the documentation:
> >
> > class SimpleXMLRPCServer(       addr[, requestHandler[,
> > logRequests[allow_none[, encoding]]]])
> >
> > I'm not sure how to specify the allow_none value or it's type, how can
> > i find out more?
> >
> > Thanks for the help!
> >
> > Regards,
> > Ken
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>



More information about the Python-list mailing list