Spons
Spons

Reputation: 1591

How to prevent SSL error on Ruby windows

ruby version: ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]

Error: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Code used for the test:

url = URI.parse("https://www.google.com/")
http = Net::HTTP.new(url.host, url.port)
http.open_timeout = 10
http.read_timeout = 10
path = url.path
path = '/' if path == ''
path += '?' + url.query unless url.query.nil?
http.use_ssl = true
request = Net::HTTP::Get.new(path, nil)
response = http.request(request)
puts response.inspect

I have tried about 2 google pages of solutions and the gem where i just submitted an issue: https://github.com/liveeditor/net_http_ssl_fix/issues/2

I've tried manual adding the certificat, adding environment variables, gems that claim to fix it and all other solutions on the first 2 pages of google.

Please let me know what more information is required to help me fix this!

Upvotes: 1

Views: 697

Answers (1)

Ka Mok
Ka Mok

Reputation: 1988

Try this solution:

https://gist.github.com/fnichol/867550

Essentially, download the cacert.pem file. Then set your system env variable SSL_CERT_FILE to the location.

Although this solution worked for me a few months back, I recently had a Windows update on both my laptop and Desktop and it's yielding this problem when I use open_uri.

Let me know how this worked out for you.

Upvotes: 1

Related Questions