2016-12-02 125 views
1

我刚刚安装了ruby,并且一直在关注Ruby教程。我开始这个教程:https://www.distilled.net/resources/web-scraping-with-ruby-and-nokogiri-for-beginners/Ruby,HTTParty,SSL错误

在那里我得到了SSL错误,所以我使用的指南在http://guides.rubygems.org/ssl-certificate-update/

我的问题是,虽然,我的版本是2.6.7红宝石当我问的版本,但是当我运行这个代码:

require 'Nokogiri' 
require 'HTTParty' 
require 'JSON' 
require 'Pry' 
require 'csv' 

page = HTTParty.get('https://google.com/') 
Pry.start(binding) 

我得到这个错误

C:\Ruby22\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/Tom/RubymineProjects/projectone/projectone.rb 
C:/Ruby22/lib/ruby/2.2.0/net/http.rb:923:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError) 
    from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:923:in `block in connect' 
    from C:/Ruby22/lib/ruby/2.2.0/timeout.rb:73:in `timeout' 
    from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:923:in `connect' 
    from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:863:in `do_start' 
    from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:852:in `start' 
    from C:/Ruby22/lib/ruby/2.2.0/net/http.rb:1375:in `request' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/httparty-0.14.0/lib/httparty/request.rb:118:in `perform' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/httparty-0.14.0/lib/HTTParty.rb:560:in `perform_request' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/httparty-0.14.0/lib/HTTParty.rb:486:in `get' 
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/httparty-0.14.0/lib/HTTParty.rb:598:in `get' 
    from C:/Users/Tom/RubymineProjects/projectone/projectone.rb:7:in `<top (required)>' 
    from -e:1:in `load' 
    from -e:1:in `<main>' 

这似乎是使用2.2.0,我仍然试图谷歌如何卸载一个版本,但STIL我不确定该怎么做?任何帮助?

我在Ruby Mine中运行脚本(如果有帮助的话)。

我运行Windows 10

+0

红宝石的当前稳定版本是'2.3.3' ......没有红宝石'2.6.7' – FeifanZ

+0

为了澄清,'宝石-v'为2.6 .7和'ruby -v'是2.2? – orde

+0

'SSL_connect'错误意味着它连接到服务器,但服务器没有响应有效的SSL证书。你应该确定为什么是这种情况......也许你的网络配置中有一些东西? – FeifanZ

回答

0

来源:How do I make HTTParty ignore SSL?

在最新HTTParty,您可以使用验证选项来禁用SSL验证;

HTTParty.get("#{ @settings.api_server }#{ url }", :verify => false).parsed_response" 

注意使用:verify => false

+0

除非你不想在生产中做到这一点...... –