SSLv3在使用机械化登录到flight.com时读取服务器证书错误



我正在尝试使用机械化和Ruby在Windows7机器中执行以下代码。

require 'mechanize'
a = Mechanize.new { |agent|
  # Flickr refreshes after login
  agent.follow_meta_refresh = true
}
a.get('https://www.flickr.com/') do |home_page|
  signin_page = a.click(home_page.link_with(:text => /Sign In/))
  puts signin_page.uri
  my_page = signin_page.form_with(:id => 'mbr-login-form') do |form|
    username_field = form.field_with(:id => 'login-username')
    username_field.value = 'some_username' 
    password_field = form.field_with(:id => 'login-passwd')
    password_field.value = 'some_password' 
  end.submit
end

我收到以下错误消息,

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent/ssl_reuse.rb:70:in `connect': SSL_connect
SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent/ssl_reuse.rb:70:in `block in
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent/ssl_reuse.rb:70:in `connect'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/net/http.rb:751:in `start'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:631:in `connection_for'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize/http/agent.rb:259:in `fetch'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mechanize-2.7.3/lib/mechanize.rb:440:in `get'
        from first.rb:19:in `<main>'

我安装了gem"Certified",但仍然出现错误。有什么见解吗?

看起来大多数公司都不再使用SSLv3了,我不得不告诉mechanize显式使用ssl_version='TLSv1'来解决这个问题。

a = Mechanize.new {|a| a.ssl_version, a.verify_mode = 'TLSv1',OpenSSL::SSL::VERIFY_NONE}

感谢这篇文章提供的真知灼见。

由于目标站点不再支持SSLv3,您遇到了此问题。在谷歌上搜索一下如何手动添加-信任-启动-更新.md可能会找到你的解决方案。我提前道歉,我没有在Windows上使用Ruby,所以我不能复制。在Linux中,这个问题通常通过更新openssl来解决,正如我在本文中回答的那样。

相关内容

  • 没有找到相关文章

最新更新