简体   繁体   English

使用ruby机械化gem时发生SSL重用错误

[英]SSL Reuse error when using ruby mechanize gem

I had my mechanize script running for roughly 3 hours before I got the following error: 在出现以下错误之前,我的机械化脚本运行了大约3个小时:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent- 
2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `initialize': 
A connection attempt failed because the connected party did not properly 
respond after a period of time, or established connection failed because
connected host has failed to respond. - connect(2) (Errno::ETIMEDOUT)

I'm assuming it's due to the fact that it's been running for 2-3 hours but was wondering if anyone had any special insight about the error 我认为这是因为它已经运行了2-3个小时,但我想知道是否有人对此错误有任何特殊的见解

Here is my script 这是我的剧本

require 'rubygems'
require 'mechanize'

def next_button(web_page)
  web_page.page.search('.next a').each do |next_button|
    web_page.click(next_button)
    web_page.page.search('.listing_content').each |info|
      get_info(info)
    end
  next_button(web_page)
  end
end

def get_info(info)
  infos = info.at_css('.url').text.strip
  address = info.css('.street-address').text.strip
  city = info.css('.locality').text.strip
  state = info.css('.region').text.strip 
  zip = info.css('.postal-code').text.strip
end

web_page = Mechanize.new                     
web_page.user_agent_alias = "Linux Firefox"
web_page.get(HOME_URL)

web_page.page.search('.page-navigation a').each do |pagination_link|
 web_page.page.search('.categories-list a').each do |link|  

    web_page.click(link)
    web_page.page.search('.listing_content').each do |info|  

      get_info(info)
    end
    next_button(web_page, worksheet)
  end

  web_page.click(pagination_link)
end    

Thanks for any help in advance. 感谢您的任何帮助。

In my opinion persistent connections are more trouble than they're worth. 在我看来,持久连接比它们值得的麻烦更多。 When this happens to me I check to make sure I have the latest version of mechanize, and if it still happens, I fall back to mechanize 1.0.0 which doesn't use persistent connections. 当发生这种情况时,我会检查以确保我具有最新版本的机械化,如果仍然发生,我会退回到机械化1.0.0,它不使用持久连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM