Skip to content

Instantly share code, notes, and snippets.

@zzak
Created January 19, 2012 23:48
Show Gist options
  • Save zzak/1643808 to your computer and use it in GitHub Desktop.
Save zzak/1643808 to your computer and use it in GitHub Desktop.
why does mechanize hate me?
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:70:in `connect'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:70:in `block in connect'
/home/zzak/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/home/zzak/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:70:in `connect'
/home/zzak/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
/home/zzak/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:750:in `start'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:405:in `connection_for'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:616:in `request'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize/http/agent.rb:264:in `fetch'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize/http/agent.rb:853:in `response_redirect'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize/http/agent.rb:298:in `fetch'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize/http/agent.rb:853:in `response_redirect'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize/http/agent.rb:298:in `fetch'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mechanize-2.1/lib/mechanize.rb:319:in `get'
/home/zzak/work/whatever/test/whatever/test_whatever.rb:15:in `block in test_something'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/bundler/gems/vcr-11c8fb97ced4/lib/vcr/util/variable_args_block_caller.rb:9:in `call'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/bundler/gems/vcr-11c8fb97ced4/lib/vcr/util/variable_args_block_caller.rb:9:in `call_block'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/bundler/gems/vcr-11c8fb97ced4/lib/vcr.rb:142:in `use_cassette'
/home/zzak/work/whatever/test/whatever/test_whatever.rb:14:in `test_something'
/home/zzak/.rvm/gems/ruby-1.9.3-p0@whatever/gems/mocha-0.10.2/lib/mocha/integration/mini_test/version_230_to_262.rb:28:in `run'
require 'bundler/setup'
require 'fakeweb'
require 'mechanize'
require 'minitest/autorun'
require 'mocha'
require 'vcr'
VCR.configure { |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.hook_into :fakeweb
}
class MyTest < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
@agent.ca_file = '/usr/lib/ssl/certs/ca-certificates.crt'
@agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
def test_something
VCR.use_cassette('something') do
form = @agent.get("http://whatever").forms[1]
assert_equal ["field1", "field2", "field3"],form.fields.collect(&:name)
end
end
end
@trutch
Copy link

trutch commented Jan 20, 2012

I'm having similar issues. Mechanize appears to be ignoring any changes to verify_mode as well as when I add a CA. Any luck?

@zzak
Copy link
Author

zzak commented Jan 20, 2012

Are you trying to use it with VCR?

If so see drbrain/net-http-persistent#13

@trutch
Copy link

trutch commented Jan 20, 2012

Nope, just writing a script that parses a local HTTPS site.

@zzak
Copy link
Author

zzak commented Jan 20, 2012

Try using Mechanize 2.0.x?

@ghsyeung
Copy link

I tried using

agent.ca_file = ca_path

on OSX, ruby 1.9.3 with rvm and had no luck. (same SSL error)

Then, I changed it to

ca_path = File.expand_path "./cacert.pem" 
agent.agent.http.ca_file = ca_path

and I was able to access the HTTPS site.

@trutch
Copy link

trutch commented Jan 21, 2012

Works with 2.0.1, Thanks man.

@zzak
Copy link
Author

zzak commented Jan 21, 2012

Also, did you try master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment