gpt4 book ai didi

python - 将 Python 脚本转换为 Ruby 时出错

转载 作者:数据小太阳 更新时间:2023-10-29 08:13:05 24 4
gpt4 key购买 nike

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

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 调用。为此,我使用了以下代码:

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 脚本时,出现以下错误:

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

我该怎么做才能解决这个错误?

最佳答案

错误发生在转换中。我没有使用列表中的列表,而是使用字典。我解决了:

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 - 将 Python 脚本转换为 Ruby 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com