473,608 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keyword args to SimpleXMLRPCSer ver

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

~~~~~~~~~~~~~~~ ~ server.py
import SocketServer
from SimpleXMLRPCSer ver import
SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
pass

class XMLFunctions(ob ject):
def returnArgs(*arg s, **kwargs):
return kwargs.items()

# Instantiate and bind to localhost:1234
server = AsyncXMLRPCServ er(('', 8080), SimpleXMLRPCReq uestHandler)

# Register example object instance
server.register _instance(XMLFu nctions())

# run!
server.serve_fo rever()

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

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

try:
print server.returnAr gs("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.p y", line 9, in <module>
print server.returnAr gs("foo", bar="bar", baz="baz")
TypeError: __call__() got an unexpected keyword argument 'bar'

~Sean
Dec 18 '07 #1
3 4240
On Dec 17, 4:13 pm, Sean DiZazzo <half.ital...@g mail.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 SimpleXMLRPCSer ver import
SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
pass

class XMLFunctions(ob ject):
def returnArgs(*arg s, **kwargs):
return kwargs.items()

# Instantiate and bind to localhost:1234
server = AsyncXMLRPCServ er(('', 8080), SimpleXMLRPCReq uestHandler)

# Register example object instance
server.register _instance(XMLFu nctions())

# run!
server.serve_fo rever()

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

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

try:
print server.returnAr gs("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.p y", line 9, in <module>
print server.returnAr gs("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(ob ject):
def returnArgs(foo, bar=None, baz=None):
return foo, bar, baz
....
Dec 18 '07 #2

"Sean DiZazzo" <ha**********@g mail.comwrote in message
news:15******** *************** ***********@e6g 2000prf.googleg roups.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 SimpleXMLRPCSer ver import
| SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler
|
| # Threaded mix-in
| class
| AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
| pass
|
| class XMLFunctions(ob ject):
| def returnArgs(*arg s, **kwargs):
| return kwargs.items()
|
| # Instantiate and bind to localhost:1234
| server = AsyncXMLRPCServ er(('', 8080), SimpleXMLRPCReq uestHandler)
|
| # Register example object instance
| server.register _instance(XMLFu nctions())
|
| # run!
| server.serve_fo rever()
|
| ~~~~~~~~~~~~~~~ ~ client.py
| from xmlrpclib import ServerProxy, Error
|
| server = ServerProxy("ht tp://localhost:8080" , allow_none=1) # local
| server
|
| try:
| print server.returnAr gs("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.p y", line 9, in <module>
| print server.returnAr gs("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='ba z')
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**********@g mail.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 SimpleXMLRPCSer ver import
SimpleXMLRPCSer ver,SimpleXMLRP CRequestHandler

# Threaded mix-in
class
AsyncXMLRPCServ er(SocketServer .ThreadingMixIn ,SimpleXMLRPCSe rver):
pass

class XMLFunctions(ob ject):
def returnArgs(*arg s, **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 <methodCallmu st 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.returnAr gs("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
4784
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 multi-threaded Server? Is there a reason why the SimpleXMLRPCServer is not multi-threaded? Is there a plan to make it multi-threaded? Thanks for any hints in advance,
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 why this class is called "Simple". What are its limitations? I want to know if I can count on it for my project or if I would need a not-so-simple XML-RPC server. Yannick
4
2329
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 to the client, the server prints some info out to the console, such as, localhost - - "POST /RPC2 HTTP/1.0" 200 - Anyhow, is there a way I can surpress that so its not printed to the
10
1799
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 on all sequences with these semantics: def join(self, seq): T = type(self) result = T()
0
1179
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 SimpleXMLRPCServer.patch reside i run : patch -i SimpleXMLRPCServer.patch -b --verbose --dry-run SimpleXMLRPCServer.py and i get : Hmm...patch: **** unexpected end of hunk at line 47
0
1634
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 get the client IP address. I have searched a long time the Internet but couldn't find a _simple_ solution :-) #Code
0
1216
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 TotoSimpleXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
3
7228
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 will simply hold a queue with files to process. The clients will ask for the next file. Do I have to sync access to the queue or is the server not threaded at all? regards,
9
3268
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 SimpleXMLRPCServer interruptable. Basically, I have a main server that, in response to certain RPC calls, creates additional servers on different ports. I then need to be able to shut these additional servers down. I've got something like this in the...
0
8496
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8148
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8338
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6816
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
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 we have to send another system
1
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1329
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.