473,498 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keyword args to SimpleXMLRPCServer

Why is the following not working? Is there any way to get keyword
arguments working with exposed XMLRPC functions?

~~~~~~~~~~~~~~~~ server.py
import SocketServer
from SimpleXMLRPCServer import
SimpleXMLRPCServer,SimpleXMLRPCRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServer(SocketServer.ThreadingMixIn,Simp leXMLRPCServer):
pass

class XMLFunctions(object):
def returnArgs(*args, **kwargs):
return kwargs.items()

# Instantiate and bind to localhost:1234
server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler)

# Register example object instance
server.register_instance(XMLFunctions())

# run!
server.serve_forever()

~~~~~~~~~~~~~~~~ client.py
from xmlrpclib import ServerProxy, Error

server = ServerProxy("http://localhost:8080", allow_none=1) # local
server

try:
print server.returnArgs("foo", bar="bar", baz="baz")
except Error, v:
print "ERROR", v
[seans-imac:~/Desktop/] halfitalian% ./client.py
Traceback (most recent call last):
File "./XMLRPC_client.py", line 9, in <module>
print server.returnArgs("foo", bar="bar", baz="baz")
TypeError: __call__() got an unexpected keyword argument 'bar'

~Sean
Dec 18 '07 #1
3 4223
On Dec 17, 4:13 pm, Sean DiZazzo <half.ital...@gmail.comwrote:
Why is the following not working? Is there any way to get keyword
arguments working with exposed XMLRPC functions?

~~~~~~~~~~~~~~~~ server.py
import SocketServer
from SimpleXMLRPCServer import
SimpleXMLRPCServer,SimpleXMLRPCRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServer(SocketServer.ThreadingMixIn,Simp leXMLRPCServer):
pass

class XMLFunctions(object):
def returnArgs(*args, **kwargs):
return kwargs.items()

# Instantiate and bind to localhost:1234
server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler)

# Register example object instance
server.register_instance(XMLFunctions())

# run!
server.serve_forever()

~~~~~~~~~~~~~~~~ client.py
from xmlrpclib import ServerProxy, Error

server = ServerProxy("http://localhost:8080", allow_none=1) # local
server

try:
print server.returnArgs("foo", bar="bar", baz="baz")
except Error, v:
print "ERROR", v

[seans-imac:~/Desktop/] halfitalian% ./client.py
Traceback (most recent call last):
File "./XMLRPC_client.py", line 9, in <module>
print server.returnArgs("foo", bar="bar", baz="baz")
TypeError: __call__() got an unexpected keyword argument 'bar'

~Sean
PS. The same thing happens if you don't use **kwargs...

....
class XMLFunctions(object):
def returnArgs(foo, bar=None, baz=None):
return foo, bar, baz
....
Dec 18 '07 #2

"Sean DiZazzo" <ha**********@gmail.comwrote in message
news:15**********************************@e6g2000p rf.googlegroups.com...
| Why is the following not working? Is there any way to get keyword
| arguments working with exposed XMLRPC functions?
|
| ~~~~~~~~~~~~~~~~ server.py
| import SocketServer
| from SimpleXMLRPCServer import
| SimpleXMLRPCServer,SimpleXMLRPCRequestHandler
|
| # Threaded mix-in
| class
| AsyncXMLRPCServer(SocketServer.ThreadingMixIn,Simp leXMLRPCServer):
| pass
|
| class XMLFunctions(object):
| def returnArgs(*args, **kwargs):
| return kwargs.items()
|
| # Instantiate and bind to localhost:1234
| server = AsyncXMLRPCServer(('', 8080), SimpleXMLRPCRequestHandler)
|
| # Register example object instance
| server.register_instance(XMLFunctions())
|
| # run!
| server.serve_forever()
|
| ~~~~~~~~~~~~~~~~ client.py
| from xmlrpclib import ServerProxy, Error
|
| server = ServerProxy("http://localhost:8080", allow_none=1) # local
| server
|
| try:
| print server.returnArgs("foo", bar="bar", baz="baz")
| except Error, v:
| print "ERROR", v
|
|
| [seans-imac:~/Desktop/] halfitalian% ./client.py
| Traceback (most recent call last):
| File "./XMLRPC_client.py", line 9, in <module>
| print server.returnArgs("foo", bar="bar", baz="baz")
| TypeError: __call__() got an unexpected keyword argument 'bar'

In general, C function do not recognize keyword arguments.
But the error message above can be reproduced in pure Python.
>>def f(): pass
>>f(bar='baz')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in -toplevel-
f(bar='baz')
TypeError: f() takes no arguments (1 given)
>>def f(x): pass
>>f(bar='baz')
Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
f(bar='baz')
TypeError: f() got an unexpected keyword argument 'bar'

Whereas calling a C function typically gives
>>''.join(bar='baz')
Traceback (most recent call last):
File "<pyshell#6>", line 1, in -toplevel-
''.join(bar='baz')
TypeError: join() takes no keyword arguments

But I don't know *whose* .__call__ method got called,
so I can't say much more.

tjr

Dec 18 '07 #3
En Mon, 17 Dec 2007 21:13:32 -0300, Sean DiZazzo <ha**********@gmail.com>
escribió:
Why is the following not working? Is there any way to get keyword
arguments working with exposed XMLRPC functions?

~~~~~~~~~~~~~~~~ server.py
import SocketServer
from SimpleXMLRPCServer import
SimpleXMLRPCServer,SimpleXMLRPCRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServer(SocketServer.ThreadingMixIn,Simp leXMLRPCServer):
pass

class XMLFunctions(object):
def returnArgs(*args, **kwargs):
return kwargs.items()
You forget the self argument. But this is not the problem. XMLRPC does not
allow passing parameters by name, only positional parameters. See
http://www.xmlrpc.com/spec:

"If the procedure call has parameters, the <methodCallmust contain a
<paramssub-item. The <paramssub-item can contain any number of
<param>s, each of which has a <value>. "

Parameters have no <name>, just a <value>, so you can only use positional
parameters. But you can simulate keyword arguments by collecting them in a
dictionary and passing that dictionary as an argument instead.

(server side)
def returnArgs(self, x, y, other={}):
return x, y, other

(client side)
print server.returnArgs("xvalue", "yvalue", dict(foo=123, bar=234,
baz=345))

--
Gabriel Genellina

Dec 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4766
by: Marco Aschwanden | last post by:
I would like to develop a server based on python's xmlrpc. But I realized that SimpleXMLRPCServer does not spawn a thread for each request. How could the SimpleXMLRPCServer be turned into a...
9
785
by: Yannick Turgeon | last post by:
I plan to use XML-RPC to communicate between my python server and VB client. I just called a simple registered function (lambda x,y: x+y) and it worked. But I'm new to XML-RPC and I'm now wondering...
4
2310
by: codecraig | last post by:
Hi, I thought I posted this, but its been about 10min and hasnt shown up on the group. Basically I created a SimpleXMLRPCServer and when one of its methods gets called and it returns a response...
10
1783
by: David Murmann | last post by:
Hi all! I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method...
0
1172
by: Thomas G. Apostolou | last post by:
Hello all, I use Python 2.3.3 and try to patch SimpleXMLRPCServer.py with the patch i got from Python.org. so after changing to the directory where both SimpleXMLRPCServer.py and...
0
1615
by: Jeremy Monnet | last post by:
Hello, I've started python a few weeks ago, and to now everything went fine with my cookbook and a learning book. Now, I've tried the SimpleXMLRPCServer, and it worked OK untill I tried to...
0
1207
by: Juju | last post by:
Hi, First, sorry for my poor English ! I used the SimpleXMLRPCServer facility of Python to develop a multithread-server, here's part of my code : -- class...
3
7217
by: Achim Domma | last post by:
Hi, is SimpleXMLRPCServer multithreaded or how does it handle multiple clients? I want to implement a simple server which will be queried by multiple processes for work to be done. The server...
9
3261
by: Bret | last post by:
I'm coming back to Python after an absence and it's surprising how many things I've forgotten since wandering (against my will) into Java land. Anyway, I have a need for a way to make...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.