Errors while converting Python script to Ruby

2019-07-01 10:21发布

问题:

I am using a Python script which uses xmlrpclib:

import xmlrpclib
srv = xmlrpclib.ServerProxy("http://demo.myslice.info:7080/", allow_none=True)

# authentication token
auth = {"AuthMethod": "password", "Username": "guest", "AuthString": "guest"}
ret = srv.Get(auth, "slice", [["slice_hrn", '=', "ple.upmc.myslicedemo"]], {}, ["slice_hrn"])
print ret

I want to make a similar XML-RPC call using Ruby. For this purpose I have used the following code:

require "xmlrpc/client"
require "pp"

XMLRPC::Config.module_eval do
    remove_const :ENABLE_NIL_PARSER
    const_set :ENABLE_NIL_PARSER, true
end

ret = XMLRPC::Client.new2("http://demo.myslice.info:7080/")

auth = {"AuthMethod" => "password", "Username" => "guest", "AuthString" => "guest"}

pp ret.call("Get", auth, "slice", {"slice_hrn" => "ple.upmc.myslicedemo"}, ["slice_hrn"])

When I run this Ruby script I get the following error:

.../xmlrpc/client.rb:414:in `call': error (XMLRPC::FaultException)

What can I do to fix this error?

回答1:

The Error was in the conversion. Instead of list inside list, I used dictionary. I solved it:

require "xmlrpc/client"
require "pp"

XMLRPC::Config.module_eval do
    remove_const :ENABLE_NIL_PARSER
    const_set :ENABLE_NIL_PARSER, true
end

ret = XMLRPC::Client.new2("http://demo.myslice.info:7080/")

auth = {"AuthMethod" => "password", "Username" => "guest", "AuthString" => "guest"}

pp ret.call("Get", auth, "slice", [["slice_hrn", "=" ,"ple.upmc.myslicedemo"]], {}, ["slice_hrn"])