提问人:Nikita Sharma 提问时间:9/13/2022 最后编辑:the Tin ManNikita Sharma 更新时间:6/10/2023 访问量:929
如何修复 OpenSSL::SSL::SSLError:SSL_connect返回=1 errno=0 state=error:没有可用的协议
How to fix OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: no protocols available
问:
当使用 Rails 中的 postmark-mailer gem 使用 deliver-later 方法由邮件触发时,我收到此错误。
2022-09-13T12:03:19.061Z 45075 TID-osgak45wb PostmarkMailer::DeliveryJob JID-031252f83654da580e4d3fcf INFO: start
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb PostmarkMailer::DeliveryJob JID-031252f83654da580e4d3fcf INFO: fail: 0.131 sec
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"PostmarkMailer::DeliveryJob","queue":"mailers","args":[{"job_class":"PostmarkMailer::DeliveryJob","job_id":"08138389-7cc8-4f0a-84c8-4cfbe0869cf4","provider_job_id":null,"queue_name":"mailers","priority":null,"arguments":[{]},\"track_opens\":\"true\",\"_aj_symbol_keys\":[\"from\",\"to\",\"template_id\",\"template_model\",\"track_opens\"]}],\"executions\":0,\"locale\":\"en\"}],\"retry\":true,\"jid\":\"031252f83654da580e4d3fcf\",\"created_at\":1663065224.6059873,\"enqueued_at\":1663070599.0592043,\"error_message\":\"SSL_connect returned=1 errno=0 state=error: no protocols available\",\"error_class\":\"OpenSSL::SSL::SSLError\",\"failed_at\":1663065241.922269,\"retry_count\":7,\"retried_at\":1663068011.4937775}"}
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb WARN: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: no protocols available
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb WARN: ~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/protocol.rb:44:in `connect_nonblock'
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb WARN: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: no protocols available
2022-09-13T12:03:19.192Z 45075 TID-osgak45wb WARN: ~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/protocol.rb:44:in `connect_nonblock'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/protocol.rb:44:in `ssl_socket_connect'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:996:in `connect'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:919:in `start'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:1470:in `request'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:1493:in `send_entity'
~/.rvm/rubies/ruby-2.6.4/lib/ruby/2.6.0/net/http.rb:1281:in `post'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/http_client.rb:30:in `block in post'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/http_client.rb:86:in `block in do_request'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/http_client.rb:85:in `synchronize'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/http_client.rb:85:in `do_request'
~.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/http_client.rb:30:in `post'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/api_client.rb:244:in `block in deliver_with_template'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/client.rb:39:in `with_retries'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/postmark-1.14.0/lib/postmark/api_client.rb:243:in `deliver_with_template'
~/.rvm/gems/ruby-2.6.4@orbidal/bundler/gems/postmark_mailer-152b64d07df2/lib/postmark_mailer/message_delivery.rb:13:in `deliver_now'
~/.rvm/gems/ruby-2.6.4@orbidal/bundler/gems/postmark_mailer-152b64d07df2/lib/postmark_mailer/delivery_job.rb:8:in `perform'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/activejob-5.1.6/lib/active_job/execution.rb:37:in `block in perform_now'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:108:in `block in run_callbacks'
~/.rvm/gems/ruby-2.6.4@orbidal/gems/i18n-1.1.1/lib/i18n.rb:284:in `with_locale'
这是我的 Ruby 和 OpenSSL 环境:
Ruby: 2.6.4p104 (2019-08-28 revision 67798) [x86_64-linux]
RubyGems: 3.0.3
Bundler: 2.2.25
Compiled with: OpenSSL 1.1.1f 31 Mar 2020
Loaded version: OpenSSL 1.1.1f 31 Mar 2020
SSL_CERT_FILE: /usr/lib/ssl/cert.pem
SSL_CERT_DIR: /usr/lib/ssl/certs
With that out of the way, let's see if you can connect to rubygems.org…
Bundler connection to rubygems.org: success ✅
RubyGems connection to rubygems.org: success ✅
Ruby net/http connection to rubygems.org: success ✅
Hooray! This Ruby can connect to rubygems.org. You are all set to use Bundler and RubyGems.
答:
0赞
Pawan Bharti
9/14/2022
#1
将以下代码插入到第 1 行的文件中:application_controller.rb
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
评论
1赞
mechnicov
9/19/2022
可能是不安全的解决方案
0赞
Pawan Bharti
9/20/2022
是的,它是不安全的,但在本地,它是绕过该问题的绝佳解决方案。
1赞
Patrick Mevzek
9/23/2022
它从来都不是解决方案,更不是一个优秀的解决方案。这只会促进糟糕的设计,而没有真正理解核心的潜在问题,更不用说解决它了。如果这样做,就会失去 TLS 的所有好处。
0赞
Nikita Sharma
6/8/2023
#2
这样可以解决问题:
首先,检查 Rails 版本及其与 Sidekiq 的兼容性。 如果兼容,请运行以下命令:
rvm get head
rvm pkg remove
rvm requirements run
rvm reinstall [ruby version you need]
如果不兼容,请检查 Ruby 或 Sidekiq 的兼容版本。
评论