【问题标题】:Please help porting xmlrpc java syntax to python请帮助将 xmlrpc java 语法移植到 python
【发布时间】:2013-07-10 02:44:09
【问题描述】:

我正在尝试锻炼如何在 python 中使用 org.apache.xmlrpc.client.XmlRpcClient。

我正在使用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);

我正在尝试遵循 python 代码,但我没有得到任何结果:

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

如何将用户名和密码传递给 python 的 ServerProxy 客户端?

非常感谢您的帮助

【问题讨论】:

    标签: java python xmlrpclib xmlrpcclient


    【解决方案1】:

    最好阅读您尝试使用的库的documentation

    这可能会起作用......可能:

    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")
    

    【讨论】:

    • 感谢您的回复,我已经解决了:from xmlrpclib import ServerProxy url = "username:password@server:port/xplrpc" s = ServerProxy(url) print s.ContentAPI.queryResult("1376")跨度>
    猜你喜欢
    • 2010-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 2011-12-17
    • 2020-08-19
    • 1970-01-01
    相关资源
    最近更新 更多