Ruby无法连接至rubygems.org

时间:2018-07-06 00:16:44

标签: ruby openssl rubygems bundler

我一直在Jekyll网站上工作一个月,但没有任何问题,但是截至本周,每次我尝试运行bundle install时,都会收到错误消息Bundler::HTTPError Could not fetch specs from https://rubygems.org。我使用的是macOS 10.13,ruby 2.5.1。

这是我的ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'

的输出
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      failed  ❌  (timed out (https://rubygems.org))
Ruby net/http connection to rubygems.org: failed  ❌

Unfortunately, this Ruby can't connect to rubygems.org. 
Even worse, we're not sure why. 

Here's the full error information:
Net::OpenTimeout: execution expired
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:915:in `start'
  (eval):90:in `<main>'
  -e:1:in `eval'
  -e:1:in `<main>'

You might have more luck using Mislav's SSL doctor.rb script. You can get it here:
https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb
Read more about the script and how to use it in this blog post:
https://mislav.net/2013/07/ruby-openssl/

运行上述脚本,我得到:

/usr/local/Cellar/ruby/2.5.1/bin/ruby (2.5.1-p57)
OpenSSL 1.0.2o  27 Mar 2018: /usr/local/etc/openssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://status.github.com:443
#<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>

最后,openssl s_client -connect rubygems.org:443 -tls1显示:

CONNECTED(00000005)
140735672206280:error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:1133:SSL alert number 70
140735672206280:error:1409E0E5:SSL routines:SSL3_WRITE_BYTES:ssl handshake failure:/BuildRoot/Library/Caches/com.apple.xbs/Sources/libressl/libressl-22.50.2/libressl/ssl/s3_pkt.c:522:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 0 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Start Time: 1530836427
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
---

我知道问题与我的SSL证书有关,但是我已经更新了openssl,ruby -ropenssl -e "puts OpenSSL::SSL::SSLContext::METHODS.grep(/.+\d$/).sort"显示我确实有TLSv1_2,所以我不知道为什么它不起作用。 / p>

这几天我一直在绞尽脑汁-任何帮助将不胜感激!谢谢!

更新:还不到两周,这个问题不断消失并再次出现。前几天,我重新启动了Mac,一切正常。今天,我遇到了一个全新的错误:

$ ruby -ropen-uri -e 'eval 

open("https://git.io/vQhWq").read'
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.0.2o  27 Mar 2018
Loaded version: OpenSSL 1.0.2o  27 Mar 2018
SSL_CERT_FILE:  /usr/local/etc/openssl/cert.pem
SSL_CERT_DIR:   /usr/local/etc/openssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      success ✅
Ruby net/http connection to rubygems.org: success ✅

Although your Ruby installation and RubyGems can both connect to rubygems.org, Bundler is having trouble. The most likely way to fix this is to upgrade Bundler by running `gem install bundler`. Run this script again after doing that to make sure everything is all set. If you're still having trouble, check out the troubleshooting guide at http://ruby.to/ssl-check-failed 
(eval):136: warning: constant OpenSSL::SSL::SSLContext::METHODS is deprecated

然后我按照说明进行操作,运行$ gem install bundler,并获得:

ERROR:  Could not find a valid gem 'bundler' (>= 0) in any repository

这是怎么回事?

3 个答案:

答案 0 :(得分:4)

在同时运行rvm和brew的$ bundle时,我不断收到“在获取https://rubygems.org/quick/Marshal.4.8/puma-3.11.4.gemspec.rz(执行到期)时出现网络错误。

运行$ ruby​​ -ropen-uri -e'eval open(“ https://git.io/vQhWq”)。read'


    Bundler connection to rubygems.org:       failed  ❌  (execution expired)
    RubyGems connection to rubygems.org:      success ✅
    Ruby net/http connection to rubygems.org: success ✅

运行$ bundle --verbose


    HTTP GET https://index.rubygems.org/versions
    Net::OpenTimeout: execution expired
    /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'

是哪个引导我到此页面的:Use Ruby DNS resolver to handle DNS timeout in Net::HTTP 表示要在您的代码中添加“ resolv-replace”。将其添加到http.rb解决了我的问题,但是我知道这不是最好的解决方案。我在此page上进行了所有尝试,但是在花了一天的时间之后,添加resolv-replace为我解决了它。

我正在使用gem -v 2.7.7,ruby -v ruby​​ 2.5.1p57和osx 10.9.5。

答案 1 :(得分:0)

对于Mac OS,更改为以下配置即可。

系统偏好设置>网络>高级> TCP / IP>配置 IPv6:仅本地链接

更多信息:https://rob.co.bb/posts/2018-10-22-yak-shave-gem-install-issue/

答案 2 :(得分:0)

我也考虑了很多(我运行的是 Ubuntu VortualBox VM)。 修复它的方法是简单地禁用 ipv6(从 UI)并重新启动网络。

systemctl restart NetworkManager