问题
This is nearly a duplicate of:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
but specific to a Rails 4 and Ruby 2 environment. I figure it is appropriate to make a new question because the solutions that worked on my machine for previous environments no longer appear to work after the updates to Rails and Ruby.
The Problem
When making a Net/HTTP SSL request to the tune of:
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)
I receive the
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
error. I've tried out the solutions in the referenced question that worked in the previous environments, to no avail.
回答1:
Try setting the certificate in environment i.e ENV
see it that help something like this
ENV['SSL_CERT_FILE'] = "your certificate path"
回答2:
Looks like it a typo - it should be an https:// protocol in the URI on the first line (and not http://)
来源:https://stackoverflow.com/questions/18321740/rails-4-and-ruby-2-net-http-ssl-request-opensslsslsslerror-ssl-connect-ret