简体   繁体   English

Ruby的open方法的OpenSSL :: SSL :: SSLError

[英]OpenSSL::SSL::SSLError with Ruby's open method

I'm trying to get an https page with Ruby's open method: 我正在尝试使用Ruby的open方法获取一个https页面:

response = open("https://example.com", 'User-Agent' => 'somebot').read

Sometimes it succeeds, but sometimes I get this error: 有时它会成功,但有时会出现此错误:

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed
from /usr/local/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock' 

What's the reason this is happening and how come for some websites it works and for some it doesn't? 发生这种情况的原因是什么?它对某些网站有效,对某些网站无效吗?

It's in the error message: 在错误消息中:

error: certificate verify failed

When you connect to some server using secure connection (https), all certificates in the certificate chain are checked for their validity up to the root certificate. 当您使用安全连接(https)连接到某些服务器时,将检查证书链中的所有证书的有效性,直到根证书为止。 If any of the certificates in the chain does not pass validity or the root certificate is not trusted root certificate, you get that error. 如果链中的任何证书未通过有效性,或者根证书不是受信任的根证书,则会出现该错误。

If you are on OSX and use RVM, see this readme . 如果您使用的是OSX并使用RVM,请参阅此自述文件 Alternatively, read about the issue here . 或者,在此处阅读有关该问题的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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