Excon::Error::Socket: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)

Excon::Error::Socket: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)

我正在尝试使用 fog-google 将图像上传到我的 google 云存储。 我的代码如下所示:

config.paperclip_defaults = {
  storage: :fog,
  fog_host: "https://#{ENV.fetch('GOOGLE_STORAGE_BUCKET')}.storage.googleapis.com",
  fog_credentials: {
      google_storage_access_key_id: ENV.fetch('GOOGLE_STORAGE_ID'),
      google_storage_secret_access_key: ENV.fetch('GOOGLE_STORAGE_SECRET'),
      provider: 'Google' },
  fog_directory: ENV.fetch('GOOGLE_STORAGE_BUCKET') }

但是,我总是收到这个错误: Excon::Error::Socket: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)

好像连接没有建立成功。

这是错误日志:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/ssl_socket.rb:117:in `connect_nonblock'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/ssl_socket.rb:117:in `initialize'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/connection.rb:404:in `new'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/connection.rb:404:in `socket'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/connection.rb:101:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/middlewares/mock.rb:48:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/middlewares/instrumentor.rb:26:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/middlewares/base.rb:16:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/middlewares/base.rb:16:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/middlewares/base.rb:16:in `request_call'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/excon-0.59.0/lib/excon/connection.rb:250:in `request'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/fog-core-1.45.0/lib/fog/core/connection.rb:81:in `request'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/fog-xml-0.1.3/lib/fog/xml/connection.rb:9:in `request'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/fog-google-0.6.0/lib/fog/storage/google_xml/real.rb:103:in `request'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/fog-google-0.6.0/lib/fog/storage/google_xml/requests/head_object.rb:36:in `head_object'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/fog-google-0.6.0/lib/fog/storage/google_xml/models/files.rb:81:in `head'
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/paperclip-5.1.0/lib/paperclip/storage/fog.rb:65:in `exists?'

这是因为您正在尝试访问 url https,但在您的情况下未能验证 ssl。

尝试添加 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

编辑 - 对于您对 中间人攻击

的关注

您还可以通过以下步骤添加 ssl 证书来验证您的应用程序

  • 下载 https://curl.haxx.se/ca/cacert.pem 到 path_to_file\cacert.pem。确保将其保存为 .pem 文件,而不是文本文件。

  • 设置环境变量:SSL_CERT_FILE = path_to_file\cacert.pem

  • 重新启动所有 ruby / rails 应用程序并立即重试访问它。

当我从 windows 切换到 Linux 时它起作用了。

使用 Windows Linux 子系统。禁用 IPV6 对我有用(对于 hyper-V)。