I have a script that when run in the console performs a series of api calls and it works wonderfully. But when I run it on the server I get a "getaddrinfo: A non-recoverable error occurred.." error
here's the piece of my code that seems to be causing problems:
require "uri"
require "net/http"
require "json"
uri = URI("https://api.domain.com/location/of/api_call/data.json?other=1&query=1&stuff=1")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
headers = {"Range" => "bytes=1000-",
"Api-Key" => API_KEY,
"X-Api-Secret" => API_SECRET}
response = ""
res = http.get(uri.path + "?" + uri.query, headers) do |data|
response += data
end
if res.code.to_i === 200
response = JSON.parse(response)
else
response = {"error" => "api call failed"}
end
Fairly simple... I had to massage the http and res object a bit to get the desired results. It works great from the console, but when I launch the server I get errors.
context: I'm running a Dashing dashboard which uses rufus-scheduler to schedule jobs. This is a job that I have scheduled to run ever 30 minutes. Dashing also uses a Thin server instead of Unicorn.
Here's the full error I get:
scheduler caught exception:
getaddrinfo: A non-recoverable error occurred during a database lookup.
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `initialize'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `open'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:878:in `block in connect'
c:/Ruby2.0.0/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:877:in `connect'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:851:in `start'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:1367:in `request'
c:/Ruby2.0.0/lib/ruby/2.0.0/net/http.rb:1126:in `get'
c:/path/to/file.rb: 215:in `block in <top (required)>'
Note: line 215 is on the "res = ..."
UPDATE:
I did an nslookup on the api address and got
*** Default servers are not available
Server: UnKnown
Address: 127.0.0.1