Search code examples
javapythonxmlrpclibxmlrpcclient

Please help porting xmlrpc java syntax to python


I'm trying to workout how to use org.apache.xmlrpc.client.XmlRpcClient in python.

I'm using code in https://github.com/mcasperson/vaultdemo/blob/master/src/main/java/com/redhat/ecs/App.java :

final XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL(args[0]));
config.setBasicUserName(args[1]);
config.setBasicPassword(args[2]);

final XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);

final Object[] params = new Object[] {"1376"};
final String retValue = (String) client.execute("ContentAPI.queryResult", params);

I was trying following python code, but I'm not getting anywhere:

from xmlrpclib import ServerProxy
s = ServerProxy(url)
print s.client.execute("ContentAPI.queryResult",1376)

What how do I pass the username and password to python's ServerProxy client?

Your help is much appreciated


Solution

  • It'd be a good idea to read the documentation of the library you're trying to use.

    This might work ... possibly:

    import xmlrpclib
    
    conn_settings = \
    {
        "user" : "noob",
        "pass" : "1234",
        "host" : "localhost",
        "port" : 8080,
        "path" : ""
    }
    
    conn_str = "http://" + ("%(user)s:%(pass)s@" % conn_settings if(conn_settings.get("user", "")) else "") + "%(host)s:%(port)d%(path)s" % conn_settings
    print "Connecting using: %s" % conn_str
    
    client = xmlrpclib.ServerProxy(conn_str)
    
    print "You can call this"
    print client.system.listMethods()
    
    print "Trying Query"
    print client.ContentAPI.queryResult("1376")