2013-07-10 61 views
0

我正在嘗試如何在python中使用org.apache.xmlrpc.client.XmlRpcClient。請幫助將xmlrpc java語法移植到python

我使用的代碼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客戶端?

你的幫助是非常讚賞

回答

0

這將會是閱讀你想使用該庫的documentation一個好主意。

這可能會實現...可能:

import xmlrpclib 

conn_settings = \ 
{ 
    "user" : "noob", 
    "pass" : "1234", 
    "host" : "localhost", 
    "port" : 8080, 
    "path" : "" 
} 

conn_str = "http://" + ("%(user)s:%(pass)[email protected]" % 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") 
+0

感謝找回,我已經工作了: 從進口的xmlrpclib ServerProxy URL =「https://開頭的用戶名:密碼@服務器: port/xplrpc「 s = ServerProxy(url) print s.ContentAPI.queryResult(」1376「) –