I’ve got some Python code below that invokes an XML RPC method:
from xmlrpclib import ServerProxy
s = ServerProxy("http://localhost:8000")
s.SomeMethod('parameter')
However, what happens when the name of the method (SomeMethod) is only known at runtime? Is there any way to invoke a method when the name of the method is in a variable?
I’ve tried the following and none of them work:
s['SomeMethod']('parameter')
s.__getattr__('SomeMethod')('parameter')
getattr(s, 'SomeMethod')('parameter')
All of them return:
xmlrpclib.Fault: <Fault -32601: 'Method not found'>
Further edit: this is starting to get really strange. When I use s['SomeMethod']('parameter'), the remote server reports that I tried to invoke the XML method __getattr__.
getattrworks as expected for me.It fails if I try to get a
reprof the returned value, as the ServerProxy class does not expose a “repr” method. Thus, if from the interactive prompt, I type just:But I can do this:
(The server-side snipped used is the one from Python’s cmlrpc documentation:
http://docs.python.org/library/xmlrpclib.html )