我正在尝试理清如何使用XMLRPC :: Client类的new3方法。这就是我所拥有的:
#!/usr/bin/ruby
require "xmlrpc/client"
params = {
host: "https://192.168.1.2",
path: "rpc/api",
port: "443",
proxy_host: "",
proxy_port: "",
user: "username",
password: "password",
use_ssl: "true",
timeout: 300,
}
session = XMLRPC::Client.new3(params)
session.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
sys_ver = session.call('api.systemVersion')
users = session.call("user.listUsers", session)
如果我使用new2方法,脚本将连接并返回404错误。但是,如果我使用new3,则返回
/usr/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `open'
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
from /usr/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /usr/lib/ruby/1.9.1/net/http.rb:762:in `connect'
from /usr/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /usr/lib/ruby/1.9.1/net/http.rb:750:in `start'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:535:in `do_rpc'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:420:in `call2'
from /usr/lib/ruby/1.9.1/xmlrpc/client.rb:410:in `call'
from sat_test.rb:24:in `<main>'
我是否正确使用new3方法?
另外,如果我使用新方法,我是否需要为每个参数设置parameter = value(proxy_host =,proxy_port =等)?
答案 0 :(得分:2)
问题似乎更多,因为我的脚本编码错误。这就是我现在所拥有的:
#!/usr/bin/ruby
require "xmlrpc/client"
params = {
host: "REDACTED",
path: "/rpc/api",
use_ssl: "true",
user: "REDACTED",
pass: "REDACTED"
}
client = XMLRPC::Client.new3(params)
client.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
session = client.call('auth.login', params[:user], params[:pass])
sys_ver = session.call('api.systemVersion', session)
users = session.call("user.listUsers", session)
users.each { |uname| puts uname }
我删除了params散列中不必要的参数,并确保所有内容都被正确引用。
它有效并且只留下404错误, 是脚本的问题。但是,至少它现在连接并给了我一些东西。