RubyonRails——为什么我的rest客户端请求会引发错误?

m528fe3b  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(335)

当我发出rest客户端请求时,出现以下错误:

D:\programs\ruby\practice>ruby practice.rb
<internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require': D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)
D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/logger.rb:28: _2 is reserved for numbered parameter
D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/logger.rb:28: _3 is reserved for numbered parameter
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
        from D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types.rb:226:in `<top (required)>'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
        from D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/mime-types-3.1/lib/mime/types/columnar.rb:1:in `<top (required)>'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
        from D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rest-client-2.1.0-x64-mingw32/lib/restclient/request.rb:8:in `<top (required)>'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
        from D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rest-client-2.1.0-x64-mingw32/lib/restclient.rb:10:in `<top (required)>'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:148:in `require'
        from D:/softwares/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rest-client-2.1.0-x64-mingw32/lib/rest-client.rb:2:in `<top (required)>'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
        from practice.rb:1:in `<main>'
<internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- rest-client (LoadError)
        from <internal:D:/softwares/Ruby30-x64/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from practice.rb:1:in `<main>'

这是我的密码:

require 'rest-client'
response = RestClient.get 'https://www.linkedin.com/feed/'
puts response

有人能解决这个问题吗?谢谢你的赏识?

6yt4nkrj

6yt4nkrj1#

您有一个gem版本控制问题。在需要时得到的错误 rest-client 是:

.../mime-types-3.1/.../logger.rb:28: _1 is reserved for numbered parameter (SyntaxError)

这是创业板的一个问题 mime-types ,其中 rest-client 看情况而定。ruby在语法上引入了一个变化,以支持块中的“编号参数”,从而使 _1, _2, ... 保留字。这种变化意味着那些命名了与这种风格相匹配的变量的人( _1, _2, etc. )在ruby 2.7中得到警告。在ruby 3.0(您正在使用)中,这会导致语法错误。
版本 mime-types 您正在使用的(3.1)必须具有此类代码;它在ruby 3.0之前就可以工作,但现在坏了。好消息是最新版本的 mine-types ,3.3.1,与ruby 3配合使用。您只需更新您的gem:

D:> gem update mime-types
Updating installed gems
Updating mime-types
Fetching mime-types-3.3.1.gem
Successfully installed mime-types-3.3.1

如果您使用的是bundler,则可能需要在 Gemfile 然后重新运行 bundle install 以触发更新。

相关问题