0

I am trying to execute following code in Windows 7 machine using Mechanize and Ruby.

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

I get following error message,

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

I installed gem 'Certified' but still getting error. Any insight?

Chuchoo
  • 823
  • 2
  • 17
  • 36

2 Answers2

4

Looks like most of the companies are moving away from using SSLv3, I had to tell mechanize to explicitly use ssl_version='TLSv1' to solve the problem.

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

Thanks for the insight provided by this post.

Community
  • 1
  • 1
Chuchoo
  • 823
  • 2
  • 17
  • 36
  • Great you tracked down a solution! You should accept your answer if that's what you're going with. – JonB Feb 21 '15 at 12:05
  • This worked for me, but it's easier to understand in simpler syntax. agent = Mechanize.new agent.ssl_version = 'TLSv1' agent.verify_mode = OpenSSL::SSL::VERIFY_NONE – user1071182 Aug 27 '15 at 02:48
0

You're running into this issue due to the target site no longer supporting SSLv3. A little Googling found howto-manually-add-trust-cert-to-rubygems.md may hold your solution. I apologize in advance that I don't do Ruby on Windows so I can't replicate. In Linux the problem is usually solved by updating openssl as I answered in this post.

Community
  • 1
  • 1
JonB
  • 836
  • 1
  • 11
  • 15
  • Thanks @JonB, I already tried the site you mentioned and went through all the steps but still getting the same error message. still looking for workarounds.. – Chuchoo Feb 20 '15 at 19:13