将 Python 脚本转换为 Ruby 时出错 [英] Errors while converting Python script to Ruby

查看:24
本文介绍了将 Python 脚本转换为 Ruby 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用 xmlrpclib 的 Python 脚本:

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

我想使用 Ruby 进行类似的 XML-RPC 调用.为此,我使用了以下代码:

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

当我运行这个 Ruby 脚本时,我收到以下错误:

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?

推荐答案

错误发生在转换中.我使用字典而不是列表中的列表.我解决了:

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

这篇关于将 Python 脚本转换为 Ruby 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆