简体   繁体   中英

Getting the `certificate verify failed (OpenSSL::SSL::SSLError)` erro with Mechanize object

For the below code got certificate verify failed (OpenSSL::SSL::SSLError) :

CODE

require 'mechanize'

agent = Mechanize.new

#{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}

agent.set_proxy('3.209.30.25', 80)
agent.ssl_version='SSLv3'
agent.verify_mode= OpenSSL::SSL::VERIFY_PEER

page = agent.get "https://gegsltraining.aravo.com/"

Error

C:/Ruby193/lib/ruby/gems/1.9.1/gems/net-http-persistent-2.8/lib/net/http/persist
ent/ssl_reuse.rb:70:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 rea
d server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

EDIT

I just modified code as follows:

require 'mechanize'
agent = Mechanize.new
#{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
agent.set_proxy('3.209.30.25', 80)
agent.ssl_version='SSLv3'
cert_store = OpenSSL::X509::Store.new
cert_store.add_file 'E:\WIPData\Ruby\Scripts\cacert.pem'
agent.cert_store = cert_store
agent.verify_mode= OpenSSL::SSL::VERIFY_PEER (tried OpenSSL::SSL::VERIFY_NONE none of them going good)

New Error

E:\WIPData\Ruby\Scripts>mechanizev1.rb
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2632:in `error!': 500 "Internal Server Err
or" (Net::HTTPFatalError)

How to be done that certification verification successfully? help me.

Just set your mechanize agent object.http.ca_file to point to this file.

agent.agent.http.ca_file = '/etc/ssl/certs/curl-ca-bundle.crt'

Otherway to do this, is to save the curl-ca-bundle.crt in app lib directory and then set

agent.agent.http.ca_file = 'lib/curl-ca-bundle.crt'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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