我正在尝试使用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文档之后。
我会检查mime-types
您的RestClient版本中安装了哪个版本的gem。看起来这些版本可能不兼容。快速挖掘RestClient源代码,您的堆栈跟踪就在这里发生:
https://github.com/rest-client/rest-client/blob/v1.6.7/lib/restclient/request.rb#L307
看起来像在安装的mime-types版本中,@extension_index
是指没有[]
实例方法的集合。mime类型的gem有点难以刺入,但是我认为Set正在/lib/mime/types/container.rb
(here)初始化。
因此,这意味着您有两种选择。您可以将mime类型的gem固定到Gemfile中的旧版本,也可以升级RestClient。看起来RestClient版本1.7.3删除了导致此问题的猴子补丁。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句