1

I have upgraded my rails application to ruby 2.6.2 and rails 5.2.2. After upgrade API calls are failing with the following error message. Kindly help me to solve this issue.

2.6.2 :004 > RestClient.get("https://www.google.co.in")
Traceback (most recent call last):
    2: from (irb):4
    1: from (irb):4:in `rescue in irb_binding'
NoMethodError (Failed to open TCP connection to www.google.co.in:443 (undefined method `[]' for nil:NilClass))
2.6.2 :005 > 

Gemfile

gem 'rails', '5.2.2'
gem "daemons", '1.1.9'

gem 'httpclient', '2.2.7'
gem 'jquery-rails'#, '= 2.1.4'      # match
gem 'pg', '~> 0.20'              # match
gem 'savon'#, '=2.11.2'             # new
gem 'settingslogic', '= 2.0.8'     # new
gem 'virtus', '0.5.2'              # new
gem "airbrake"#, "= 3.1.7"          # match
gem 'newrelic_rpm'#, '3.5.3.25'        # match
gem 'nokogiri'#, '=1.4.0'
gem 'bootsnap'

gem 'httparty'
gem 'rest-client'
gem 'multi_json'
gem 'mime-types', '= 1.18'


group :test, :development do
  gem 'rspec-rails'#, '= 2.12.0' # newer
  gem 'pry-byebug'#,       "= 1.1.3"
end

 group :development do
   gem 'pry-byebug'#, '= 1.1.3' # match
   gem 'thin', '= 1.3.1'     # match
end

It is working in ruby 2.6.2 irb, but not in rails console. What could be the problem?

2.6.2 :002 > require 'rest-client'
 => true 
2.6.2 :003 > RestClient.get("https://www.google.co.in")
 => <RestClient::Response 200 "<!doctype h..."> 
2.6.2 :004 >
Can Can
  • 3,644
  • 5
  • 32
  • 56
  • Can you show us your `Gemfile` ? – asimhashmi Jun 17 '19 at 07:52
  • @AsimHashmi Updated question with Gemfile details – Can Can Jun 17 '19 at 07:57
  • As a suggestion, could you try breaking this right down to a **minimal** reproduction? It seems to be an issue with either (1) the specific domain name, or (2) upgrading the ruby version, or (3) upgrading the `rest-client` version. I don't see how the version of Rails, or any of the other ~20 project dependencies you've listed, could be contributing to the issue. – Tom Lord Jun 17 '19 at 09:56
  • I *could* go ahead and diagnose this myself, but... What happens when you just `gem install rest-client` then try the above? What about on an older ruby version? – Tom Lord Jun 17 '19 at 09:57
  • I don't think its an issue with rest-client. I get the same error with HTTParty as well. – Can Can Jun 17 '19 at 10:27
  • @TomLord The same command is working in older ruby version. I mean ruby 2.0 – Can Can Jun 17 '19 at 10:28
  • OK, so that seems to imply the issue is with the ruby version. What happens if you use `2.5`? `2.4`? At what point does it break? For a little context, I just tried running the exactly command you originally showed above (`RestClient.get("https://www.google.co.in")`, using `rest-client` version `2.0.2` and ruby version `2.6.2`) and it worked fine. So maybe this is purely an issue on your network configuration, e.g. your firewall. It's really hard to diagnose given the limited information and my inability to reproduce the problem. – Tom Lord Jun 17 '19 at 11:04
  • @TomLord its working in 2.6.2 irb. but not in rails console – Can Can Jun 17 '19 at 11:11
  • What happens if you spin up a brand new rails app (`rails new`), using the same rails version? – Tom Lord Jun 17 '19 at 11:48
  • Maybe (just a guess; I haven't bothered testing this all for you) the issue relates to the locked `httpclient` version (`2.2.7`)? There have been many changes since then, which may be relevant. https://github.com/nahi/httpclient/blob/master/CHANGELOG.md – Tom Lord Jun 17 '19 at 11:53
  • Try deleting `Gemfile.lock` and then `bundle install` again – Guilherme Nunes Jun 17 '19 at 12:30
  • @TomLord No luck. its failing with httpclient 2.8.3 as well – Can Can Jun 17 '19 at 12:36
  • That issue was occurring because of the gem virtus-0.5.2 . Thanks a lot @TomLord – Can Can Jun 17 '19 at 12:43

0 Answers0