简体   繁体   中英

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. One comes default with system. The other is installed later on through rvm.

  • /usr/bin/irb (ruby 2.0.0p481)
  • /Users/user/.rvm/rubies/ruby-2.2.1/bin/irb (ruby 2.2.1p85)

When using older irb, run above code, it gives me:

#<Net::HTTPOK 200 OK readbody=true>

When using newer irb, run above code, it gives me:

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. Tried different solutions on StackOverflow but none of them seems fix the problem.

将OSX升级到El Capitan后,我通过rvm重新安装了Ruby 2.2.3,并且可以正常工作。

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