getaddrinfo:发生了不可恢复的错误 - ruby​​ net / http请求

时间:2014-07-01 00:58:33

标签: ruby sockets net-http dashing

我有一个脚本,当在控制台中运行时会执行一系列api调用,并且它运行得非常好。但是当我在服务器上运行它时,我得到一个" getaddrinfo:发生了不可恢复的错误。"错误

这是我的代码中似乎导致问题的部分:

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

相当简单......我不得不按下http和res对象以获得所需的结果。它在控制台上工作得很好,但是当我启动服务器时出现错误。

上下文: 我正在运行一个Dashing仪表板,它使用rufus-scheduler来安排作业。 这是我计划在30分钟内完成的工作。 Dashing还使用Thin服务器而不是Unicorn。

这是我得到的完整错误:

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

注意:第215行位于&#34; res = ...&#34;

更新

我在api地址上做了nslookup并得到了

*** Default servers are not available
Server:  UnKnown
Address:  127.0.0.1

0 个答案:

没有答案