473,573 Members | 4,459 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 4234
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
4776
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...
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...
4
2325
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...
10
1796
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
1177
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...
0
1628
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
7225
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...
9
3266
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...
0
7741
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7661
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7978
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. ...
1
7730
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...
0
8028
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...
0
5252
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3692
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
987
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...

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.