Basa Sai ram
Basa Sai ram

Reputation: 53

Why does my rest-client request raise an error?

I am getting the following error when I make a rest-client request:

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

Here is my code:

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

Can anyone solve this one in return thanks for appreciation?

Upvotes: 1

Views: 2362

Answers (2)

Basa Sai ram
Basa Sai ram

Reputation: 53

For every require load error execute the below command to install gems for ruby programs.

ruby -S gem install <gem-name>

in my case it is.

ruby -S gem install rest-client

Upvotes: 2

rmlockerd
rmlockerd

Reputation: 4136

You are having a gem versioning issue. The error you are getting when you require rest-client is:

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

This is a problem in the gem mime-types, which rest-client depends on. Ruby introduced a change in syntax to support 'numbered parameters' in blocks that made _1, _2, ... reserved words. That change meant that people who had named variables matching that style (_1, _2, etc.) got a warning in Ruby 2.7. In Ruby 3.0 (which you are using), that now causes a syntax error.

The version of mime-types you are using (3.1) must have had code of that kind; it worked prior to Ruby 3.0, but now breaks. The good news is that the latest version of mine-types, 3.3.1, works with Ruby 3. You just need to update your 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

If you are using bundler, you might need to change the version in your Gemfile and re-rerun bundle install to trigger the update.

Upvotes: 2

Related Questions