Errors while converting Python script to Ruby

拥有回忆 提交于 2019-12-10 21:31:37

问题


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


来源:https://stackoverflow.com/questions/13122615/errors-while-converting-python-script-to-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!