470,647 Members | 1,268 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

XML-RPC

Ben
Hi all,

I think this is a very simple problem.. I'm trying to run an xml-rpc
server given in SimpleXMLRPCServer.py file that comes with Python and
wrote a very simple client to interact with it but it's giving me
errors.

The server code is as follows:

#!/usr/local/bin/python2.2

from SimpleXMLRPCServer import *

# Install an instance with custom dispatch method:

class Math:
def _dispatch(self, method, params):
if method == 'pow':
return apply(pow, params)
elif method == 'add':
return params[0] + params[1]
else:
raise 'bad method'
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(Math())
server.serve_forever()

Client code:
#!/usr/local/bin/python2.2

import xmlrpclib
myserver = xmlrpclib.Server("http://localhost:8000")

p= [2,2]
print myserver._dispatch("add",p)

The error I get:
.......
.......
xmlrpclib.Fault: <Fault 1: 'bad method:None'>

What have I done wrong?

Thanks
Ben
Jul 18 '05 #1
1 2473
Ben wrote:
...
def _dispatch(self, method, params):
if method == 'pow':
return apply(pow, params)
elif method == 'add':
return params[0] + params[1]
else:
raise 'bad method' ... p= [2,2]
print myserver._dispatch("add",p)


the way you've coded your server, the client should call myserver.add(2,2)
and NOT what you've coded on the client side.

To see why add a simple print of method and params as the first line
of _dispatch and you'll see:

for the call to .add(2,2):
dispatching 'add' (2, 2)

for the call to ._dispatch('add', [2,2]):
dispatching '_dispatch' ('add', [2, 2])

i.e. the way you call it string '_dispatch' becomes the method and the tuple
of args that ends in params isn't what you apparently think it should be.
Alex

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Phil Powell | last post: by
reply views Thread by Stylus Studio | last post: by
5 posts views Thread by Kurt Bauer | last post: by
5 posts views Thread by laks | last post: by
9 posts views Thread by Lie | last post: by
10 posts views Thread by =?Utf-8?B?YzY3NjIyOA==?= | last post: by
reply views Thread by Jacker | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.