I have a system which uses XMLRPC to execute zope methods remotely for administrative purposes. I shamelessly borrowed the xmlrpcBasicAuth code (thanks Amos and Chris) used by ZSyncer to provide a xmlrpc server proxy with BasicAuthTransport. To execute a method remotely, I first create a server server = Server( url, username='...', password='...') where url references the object upon which the method is to be applied or the object which contains the object to be executed. To execute a method with id of foo, on then executes getattr( server, 'foo')( [params] ) where params is a dictionary containing the name/value pairs needed by the method. This works for DTML methods, but fails for Python Scripts with diagnostics related to mismatched counts of parameters. For the moment, I've worked around the problem with a DTML method wrapper for my python script, but thats ugly! What's the right Python Script interface to be called by XMLRPC?
Hi,
getattr( server, 'foo')( [params] )
Is this the statement you actually use? If so: you are passing a single argument, which is a list with a single element. This is not what you want. Use getattr( server, 'foo')( **params ) which will pass teh elements of the dict as keyword parameters. -- Regards Hartmut Goebel | Hartmut Goebel | We build the crazy compilers | | h.goebel@crazy-compilers.com | Compiler Manufacturer |
Ooops-- right you are. Thanks. -d On Sat, 10 Jan 2004, Hartmut Goebel wrote:
Hi,
getattr( server, 'foo')( [params] )
Is this the statement you actually use? If so: you are passing a single argument, which is a list with a single element. This is not what you want.
Use getattr( server, 'foo')( **params )
which will pass teh elements of the dict as keyword parameters.
-- Regards Hartmut Goebel
| Hartmut Goebel | We build the crazy compilers | | h.goebel@crazy-compilers.com | Compiler Manufacturer |
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Hartmut Goebel wrote at 2004-1-10 10:33 +0100:
getattr( server, 'foo')( [params] )
Is this the statement you actually use? If so: you are passing a single argument, which is a list with a single element. This is not what you want.
Use getattr( server, 'foo')( **params )
which will pass teh elements of the dict as keyword parameters.
Note that XML-RPC does not support keyword arguments. -- Dieter
On Sat, 10 Jan 2004, Dieter Maurer wrote:
Hartmut Goebel wrote at 2004-1-10 10:33 +0100:
getattr( server, 'foo')( [params] )
Is this the statement you actually use? If so: you are passing a single argument, which is a list with a single element. This is not what you want.
Use getattr( server, 'foo')( **params )
which will pass teh elements of the dict as keyword parameters.
Note that XML-RPC does not support keyword arguments.
In what I am writing below, server is an XMLRPC server proxy with basic authentication transport. So, what is the right call? Suppose I have a Python Script at the remote sitei with an argument signature: def foo( a, b, c ): ... which I want to invoke via XMLRPC. How do I pass the positional arguments? If I have a DTML method foo, with keyword (that is cgi) parameters a, b, and c, I know I can invoke it remotely by writing in the invoking python script pdict = {'a':1,'b':2,'c'3} getattr( server, 'foo')([pdict]) That is, by passing the the params dictionary. Is the proper server call for a python script ptuple = (1, 2, 3,) getattr( server, 'foo')( [ptuple] )
Dennis Allison wrote at 2004-1-10 13:59 -0800:
... On Sat, 10 Jan 2004, Dieter Maurer wrote:
... Note that XML-RPC does not support keyword arguments.
In what I am writing below, server is an XMLRPC server proxy with basic authentication transport.
So, what is the right call? Suppose I have a Python Script at the remote sitei with an argument signature:
def foo( a, b, c ): ...
which I want to invoke via XMLRPC. How do I pass the positional arguments?
The same way you always pass positional arguments: foo(value_for_a, value_for_b, value_for_c) -- Dieter
Dennis Allison wrote at 2004-1-9 18:13 -0800:
... XML-RPC ... To execute a method with id of foo, on then executes
getattr( server, 'foo')( [params] )
where params is a dictionary containing the name/value pairs needed by the method.
This works for DTML methods,
Surprising...
but fails for Python Scripts with diagnostics related to mismatched counts of parameters.
When you pass a dictionary, the Python Script gets a single argument (this dictionary). Note that XML-RPC only support positional arguments and that there is no calling magic. The target gets the positional arguments as you pass them. -- Dieter
participants (3)
-
Dennis Allison -
Dieter Maurer -
Hartmut Goebel