Open SSL Errors for Ruby on Windows 7

2019-04-17 03:31发布

I'm running on Windows 7 normal OS.

Ruby, SSL, and Windows don't like each other, so simple commands like these don't work for me and it's giving me a real headache. I've tried getting RVM, updating my environmental variables, practically everything.

I don't know what the solution is. Is there a solution to install the OpenSSL gem for Ruby 1.9.3?

require 'mechanize'
agent = Mechanize.new
page = agent.get('https://any-ssl-site-here.com')
puts page

1条回答
太酷不给撩
2楼-- · 2019-04-17 04:09

So whenever you try to use libraries to access https urls on Windows they basically fail because OpenSSL doesn't know where to look for the ca_file.

The fix is pretty straight forward, get a CA Cert Bundle (my favorite is cURL's CA Bundle) and point whatever library you're going to use to it.

In the case of mechanize they do it using the #ca_file instance method.

In other words, change your code to:

require 'mechanize'
agent = Mechanize.new
agent.ca_file = "path/to/ca_bundle.crt"

page = agent.get('https://any-ssl-site-here.com')
puts page

Also, check out Luis Lavena's execellent answer to a similar question.

查看更多
登录 后发表回答