NoMethodError试图使用Ruby RestClient

NoMethodError试图使用Ruby RestClient,ruby,rest-client,Ruby,Rest Client,我正在尝试使用RestClient与API对话,我得到了以下错误和回溯: >> RestClient.post "http://localhost:8081/accounts", {}.to_json, content_type: :json, accept: :json NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}> from /Us

我正在尝试使用RestClient与API对话,我得到了以下错误和回溯:

>> RestClient.post "http://localhost:8081/accounts", {}.to_json, content_type: :json, accept: :json
NoMethodError: undefined method `[]' for #<Set: {#<MIME::Type: application/json>}>
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in `type_for_extension'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in `type_for_extension'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:278:in `block in stringify_headers'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `each'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `inject'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in `stringify_headers'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in `make_headers'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in `initialize'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `new'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in `execute'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/rest-client-1.6.7/lib/restclient.rb:72:in `post'
    from (irb):5
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Users/pupeno/.rvm/gems/ruby-2.3.1@console/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/pupeno/Documents/qredo/console/bin/rails:9:in `require'
    from /Users/pupeno/Documents/qredo/console/bin/rails:9:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'
>RestClient.post”http://localhost:8081/accounts“,{}.to_json,content_type::json,accept::json
NoMethodError:的未定义方法“[]”#
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:307:in'type_for_extension'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:312:in'type_for_extension'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:278:in'block in stringify_headers'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in'each'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in'inject'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:272:in'stringify_headers'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:92:in'make_headers'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:58:in'initialize'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in'new'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient/request.rb:33:in'execute'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/rest-client-1.6.7/lib/restclient.rb:72:in'post'
来自(irb):5
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in'start'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in'start'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in'console'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/railties-4.2.6/lib/rails/commands/commands\u tasks.rb:39:in'run\u command!'
来自/Users/pupeno/.rvm/gems/ruby-2.3。1@console/gems/railties-4.2.6/lib/rails/commands.rb:17:in`'
from/Users/pupeno/Documents/qredo/console/bin/rails:9:in'require'
from/Users/pupeno/Documents/qredo/console/bin/rails:9:in`'
from-e:1:in“load”
from-e:1:in`'

知道这里出了什么问题吗?据我所知,请求可能没有到达服务器,但我的线路如下。

我会检查您的RestClient版本安装了哪个版本的
mime类型。看起来两个版本可能不兼容。快速挖掘RestClient源代码,您的stacktrace就发生在这里:

与安装的mime类型版本类似,
@extension\u index
指的是没有
[]
实例方法的集合。mime类型gem有点难理解,但我认为集合正在
/lib/mime/types/container.rb
()中初始化


所以,在这一点上,这意味着你有两个选择。将mime类型gem固定到gem文件中的旧版本,或者升级RestClient。看起来RestClient版本删除了导致此问题的monkey补丁。

我刚刚将此gem添加到我的一个项目中。你能展示你的代码并确认api返回了什么吗?我认为空哈希{}有问题。要想获得json,请尝试在其中传递一些值,比如{'x'=>1}。要获得json。猜猜看。你能更新到更高版本的RestClient gem吗?Hola Pablo,你能更新到最新版本吗?你能试试铁轨外面吗?我尝试过最新的gem,它很有效,即使是空的{}。简化者的欢呼