I am using an API which works fine on development but timeouts when I call it from production or heroku run rails console.
I'm doing the following
url = "http://theapi.example.com"
response = RestClient.get url
Locally I get a 200 response, in proudction I get the following:
RestClient::Exceptions::OpenTimeout: Timed out connecting to server from /app/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.1/lib/restclient/request.rb:731:in
rescue in transmit' from /app/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.1/lib/restclient/request.rb:647:in
transmit' from /app/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.1/lib/restclient/request.rb:145:inexecute' from /app/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.1/lib/restclient/request.rb:52:in
execute' from /app/vendor/bundle/ruby/2.3.0/gems/rest-client-2.0.1/lib/restclient.rb:67:inget' from (irb):30 from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in
start' from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/console.rb:9:instart' from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in
console' from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /app/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in
' from script/rails:6:inrequire' from script/rails:6:in
'
The API does not support ssl, not sure it is has anything to do with it.
The API provider had Heroku's IP blocked to avoid attacks. He unblocked the IP of the request and everything worked.