Rails 4和Ruby 2 Net/HTTP SSL请求:OpenSSL::SSL::SSLError:SSL\u connect返回=1 errno=0 state=SSLv2/v3读取服务器hello A:未知协议

Rails 4和Ruby 2 Net/HTTP SSL请求:OpenSSL::SSL::SSLError:SSL\u connect返回=1 errno=0 state=SSLv2/v3读取服务器hello A:未知协议,ssl,openssl,ruby-on-rails-4,ruby-2.0,net-http,Ssl,Openssl,Ruby On Rails 4,Ruby 2.0,Net Http,这几乎是以下内容的副本: 但是特定于Rails 4和Ruby 2环境。我认为提出一个新问题是合适的,因为在我的机器上为以前的环境工作的解决方案在Rails和Ruby更新后似乎不再工作 问题 在对以下内容发出Net/HTTP SSL请求时: api_uri = URI("http://accounts.google.com/o/oauth2/token") https = Net::HTTP.new(api_uri.host, api_uri.port) https.use_

这几乎是以下内容的副本:

但是特定于Rails 4和Ruby 2环境。我认为提出一个新问题是合适的,因为在我的机器上为以前的环境工作的解决方案在Rails和Ruby更新后似乎不再工作

问题 在对以下内容发出Net/HTTP SSL请求时:

api_uri = URI("http://accounts.google.com/o/oauth2/token")
https = Net::HTTP.new(api_uri.host, api_uri.port)
https.use_ssl = true
https.ca_file = '/usr/local/etc/openssl/cert.pem' if Rails.env == "development"
https.request_get(api_uri.path)
我收到了

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol

错误。我已经尝试了参考问题中在以前的环境中有效的解决方案,但没有效果。

尝试在环境中设置证书,即
ENV
查看类似的帮助

ENV['SSL_CERT_FILE'] = "your certificate path"

看起来像是输入错误-它应该是第一行URI中的https://协议(而不是http://)