Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > xmlrpclib and SimpleXMLRPCServer questions

Reply
Thread Tools

xmlrpclib and SimpleXMLRPCServer questions

 
 
xkenneth
Guest
Posts: n/a
 
      09-12-2007
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

 
Reply With Quote
 
 
 
 
Jeff McNeil
Guest
Posts: n/a
 
      09-12-2007
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 <> 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
>

 
Reply With Quote
 
 
 
 
Jeff McNeil
Guest
Posts: n/a
 
      09-12-2007
Duh... you can pass allow_none=True to SimpleXMLRPCServer()....


On 9/12/07, Jeff McNeil <> 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 <> 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
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failure to connect in SimpleXMLRPCServer/xmlrpclib iu2 Python 5 10-22-2007 12:33 PM
XML-RPC server with xmlrpclib and mod_python Johann C. Rocholl Python 0 06-01-2006 08:14 PM
xmlrpclib and carriagereturn (\r) Jonathan Ballet Python 5 03-18-2006 01:52 PM
xmlrpclib and decoding entity references Chris Curvey Python 5 05-04-2005 10:33 PM
xmlrpclib and binary data as normal parameter strings Rune Froysa Python 3 04-20-2005 09:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57