[英]OpenSSL::SSL::SSLError: SSL_connect error on Ruby 2.2.1
Here's the code to run: 这是要运行的代码:
require "net/http"
uri = URI.parse("https://www.google.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
I got two version of irb
in my Mac OSX. 我的Mac OSX中有两个版本的
irb
。 One comes default with system. 系统自带一个默认值。 The other is installed later on through rvm.
另一个通过rvm稍后安装。
When using older irb, run above code, it gives me: 使用较早的irb时,请运行上述代码,它会为我提供:
#<Net::HTTPOK 200 OK readbody=true>
When using newer irb, run above code, it gives me: 使用较新的irb时,运行上面的代码,它会给我:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `connect'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `block in connect'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/timeout.rb:74:in `timeout'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:923:in `connect'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:852:in `start'
from /Users/user/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/http.rb:1375:in `request'
from (irb):7
from /Users/user/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'
It should be the issue of SSL is not recognized by new version of ruby. 应该是新版本的ruby无法识别SSL的问题。 Tried different solutions on StackOverflow but none of them seems fix the problem.
在StackOverflow上尝试了不同的 解决方案 ,但似乎没有一个解决问题。
将OSX升级到El Capitan后,我通过rvm重新安装了Ruby 2.2.3,并且可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.