ruby 如何修复OpenSSL::SSL::SSLError:SSL_connect returned=1 errno=0 state=error:无可用协议

to94eoyn  于 2023-06-22  发布在  Ruby
关注(0)|答案(2)|浏览(232)

我在使用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.
68bkxrlz

68bkxrlz1#

这解决了问题:
首先,检查Rails版本及其与Sidekiq的兼容性。如果兼容,则运行以下命令:

rvm get head
rvm pkg remove
rvm requirements run 
rvm reinstall [ruby version you need]

如果不兼容,请检查Ruby或Sidekiq的兼容版本。

n9vozmp4

n9vozmp42#

application_controller.rb文件的第1行插入以下代码:

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

相关问题