在Windows 7上为Ruby打开SSL错误[英] Open SSL Errors for Ruby on Windows 7

本文是小编为大家收集整理的关于在Windows 7上为Ruby打开SSL错误的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在Windows 7普通操作系统上运行.

Ruby,SSL和Windows彼此不喜欢,因此这样的简单命令对我不起作用,这给我带来了真正的头痛.我尝试获得RVM,更新我的环境变量,几乎所有内容.

我不知道解决方案是什么.是否有一个解决方案可以安装Ruby 1.9.3的OpenSSL宝石?

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

推荐答案

因此,每当您尝试使用库访问Windows上的https url时,它们基本上会失败,因为Openssl不知道在哪里寻找ca_file.

修复程序非常简单,得到一个ca cert捆绑包(我最喜欢的是 curl ca bundle )指向您要使用的任何库.

在mechanize的情况下,他们使用 #ca_file实例方法.

换句话说,将您的代码更改为:

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

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

另外,请查看 Luis Lavena的Execellent对类似问题的回答.

本文地址:https://www.itbaoku.cn/post/786675.html

问题描述

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

推荐答案

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.