我在 irb
上获得了这些命令
require 'mechanize'
agent = Mechanize.new
agent.get('https://monabo.lemonde.fr/customer/account/forgotpassword/')
我遇到了这个错误:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=unknown state: sslv3 alert handshake failure
我在 mac 上试过,它可以正常工作,但没有出现此错误。但是,它在我的计算机(运行 Linux Mint 17)上不起作用。
我尝试过的:
导出这个变量:
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
设置这个变量:
agent.agent.http.ca_file = '/etc/ssl/certs/ca-certificates.crt'
设置这个:
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
更改 ruby 版本(我目前使用的是 ruby 2.1.5p275)
这些解决方案都没有改变问题。我怀疑服务器需要特定版本的 OpenSSL。
请注意,我可以使用 mechanize
请求 https://google.com
并且它有效,但不是 https://monabo.lemonde。 fr/客户/帐户/忘记密码/
。
它在 Mac 上运行的事实可能假设我的配置有误。
编辑:这是此命令的输出:
➜ swiff git:(master) ✗ openssl s_client -connect monabo.lemonde.fr/customer/account/forgotpassword:443 -tls1 -servername monabo.lemonde.fr/customer/account/forgotpassword | openssl x509 -text -noout
gethostbyname failure
connect:errno=0
unable to load certificate
140045809014432:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE
一些其他数据:
最佳答案
服务器仅支持 SSLv3 和 TLSv1,并且仅支持密码 DES-CBC3-SHA。此密码不包含在您的 ruby 版本使用的默认密码集中,如您在 https://github.com/ruby/ruby/blob/ruby_2_1/ext/openssl/lib/openssl/ssl.rb 中所见。 . 这个设置很奇怪,因为据我所知,DES-CBC3-SHA(即 DES3)被认为比他们的密码集中的 RC4-SHA 更安全。
我试图找到一种方法来为 mechanize 对象设置密码,但我对编写 ruby 了解不多,而且系统上只有旧版本的 ruby。您可以尝试类似 agent.agent.http.ciphers = [ 'des-cbc3-sha' ]
或咨询一些 ruby 专家。
关于ruby - Mechanize 的 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29610513/