0

对于以下代码certificate verify failed (OpenSSL::SSL::SSLError)

代码

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/"

错误

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)

编辑

我只是修改了代码如下:

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)

新错误

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)

如何成功完成认证验证?帮我。

4

1 回答 1

0

只需将您的机械化代理 object.http.ca_file 设置为指向此文件。

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

否则,将 curl-ca-bundle.crt 保存在 app lib 目录中,然后设置

agent.agent.http.ca_file = 'lib/curl-ca-bundle.crt'
于 2013-01-23T08:44:51.297 回答