尝试抓取网站时出现Ruby SSL错误

时间:2017-01-22 14:05:31

标签: ruby-on-rails ruby ssl openssl rubygems

所以,基本上我试图运行这个脚本https://github.com/JeffreyATW/mbfc_crawler,它给了我 这个错误:

C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock': SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)
    from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:933:in `connect'
    from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
    from C:/Ruby23-x64/lib/ruby/2.3.0/net/http.rb:858:in `start'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:700:in `start'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:631:in `connection_for'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/net-http-persistent-2.9.4/lib/net/http/persistent.rb:994:in `request'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mechanize-2.7.5/lib/mechanize/http/agent.rb:274:in `fetch'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/mechanize-2.7.5/lib/mechanize.rb:464:in `get'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wombat-2.5.1/lib/wombat/processing/parser.rb:61:in `public_send'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wombat-2.5.1/lib/wombat/processing/parser.rb:61:in `parser_for'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wombat-2.5.1/lib/wombat/processing/parser.rb:44:in `parse'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wombat-2.5.1/lib/wombat/crawler.rb:30:in `crawl'
    from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/wombat-2.5.1/lib/wombat.rb:13:in `crawl'
    from crawler.rb:21:in `block in <main>'
    from crawler.rb:20:in `each'

我已经从Ruby Installer for Windows安装了Ruby 2.3.3。

我还为我的机器(来自同一站点)安装了DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe。

我做错了什么?谢谢你的时间。

2 个答案:

答案 0 :(得分:0)

也许它需要CA证书。

从此处将其保存在您的m / c中:concatMap

使用以下命令设置路径:

setx SSL_CERT_FILE path_where_you_have_placed_above_file

答案 1 :(得分:0)

停止使用SSLv3,并开始使用TLS 1.0(或更高版本)和Server Name Indication (SNI)

这是你在Ruby上做的事情:

class diagram

这是你应该用Ruby做什么的。注意TLS 1.0和SNI:

$ openssl s_client -connect github.com:443 -ssl3
CONNECTED(00000003)
3069617360:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:s3_pkt.c:1275:SSL alert number 40
3069617360:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:s3_pkt.c:598:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 0 bytes
---
...