【问题标题】:Getting error "getaddrinfo: No such host is known. (Socke tError)" with mechanize gem使用 mechanize gem 获取错误“getaddrinfo: No such host is known. (Socke tError)”
【发布时间】:2013-01-05 10:01:44
【问题描述】:

我尝试了以下代码:

require 'mechanize'

agent = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
    page = agent.get "https://gegsltraining.aravo.com/"
page=page.link_with(:dom_class => "button").click()

但我很糟糕得到以下错误。

D:\WIPData\Ruby\Scripts>mechanize_dowload.rb
C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persist
ent/ssl_reuse.rb:29:in `initialize': getaddrinfo: No such host is known.  (Socke
tError)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent/ssl_reuse.rb:29:in `open'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent/ssl_reuse.rb:29:in `block in connect'
        from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
        from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent/ssl_reuse.rb:29:in `connect'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:750:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent.rb:628:in `start'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent.rb:570:in `connection_for'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net
/http/persistent.rb:926:in `request'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.5.1/lib/mechanize/h
ttp/agent.rb:258:in `fetch'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mechanize-2.5.1/lib/mechanize.r
b:407:in `get'
        from D:/WIPData/Ruby/Scripts/mechanize_dowload.rb:5:in `<main>'

D:\WIPData\Ruby\Scripts>

相同的脚本在我的个人机器上完美运行,但在我的公司却不行。

你能帮我解决一下吗?

提前致谢

【问题讨论】:

  • 有人可以帮我吗?
  • 这也发生在我身上,但并非始终如一,在我的脚本中。我正在加载一个谷歌网站,它不太可能被关闭并且 DNS 解析应该已经被缓存了......它是这样的:p.defau.lt/?J6ywtrHAOcdzXY80xGIbrg

标签: ruby windows-xp mechanize mechanize-ruby


【解决方案1】:

该错误意味着 dns 无法解析。根据我的经验,这通常是因为您的网络中断了。

【讨论】:

  • 我的互联网正在运行。我在公司里,剧本在我家里运行得很好,而不是在我的办公室里。
  • 它已经启动,因为我可以在我的浏览器上打开它。
  • 也许你在做一些傻事,比如通过代理连接而不显示它。
  • 我用我的脚本也试过这个agent.set_proxy('3.209.30.25','80', user = nil, pass = nil),仍然出错。但是,是的,我检查了ping -t www.google.com 在我的终端上没有工作。所以可以做任何解决方法。可能是我的公司政策保护我解雇pingC:\&gt;ping -t www.google.com Ping request could not find host www.google.com. Please check the name and try a gain.
  • 您的问题解决了吗?我也面临同样的问题。
猜你喜欢
  • 2010-11-19
  • 2015-09-25
  • 2018-07-12
  • 2016-10-16
  • 2016-01-26
  • 1970-01-01
  • 2020-06-09
  • 1970-01-01
  • 2019-02-19
相关资源
最近更新 更多