我在使用 shopify_api gem 访问 Shopify API 时遇到问题。
发生的情况如下:
>> require "shopify_api" #=> false
>> ShopifyAPI::Base.site = "https://username:[email protected]/admin"
=> "https://username:[email protected]/admin"
>> products = ShopifyAPI::Product.find(:all)
Errno::ECONNRESET: Connection reset by peer - SSL_connect
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1026:in `get'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/connection.rb:113:in `block in request'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/connection.rb:110:in `request'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/shopify_api-3.0.1/lib/active_resource/connection_ext.rb:13:in `request_with_detailed_log_subscriber'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/connection.rb:80:in `block in get'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/connection.rb:218:in `with_auth'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/connection.rb:80:in `get'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:901:in `find_every'
from /Users/zubin/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.8/lib/active_resource/base.rb:813:in `find'
from (irb):21
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
认为这是 ruby 的 openssl 绑定的问题,我使用 RVM 安装了 openssl 并重新安装了 ruby:
rvm pkg install openssl
rvm reinstall 1.9.3-p194 --with-openssl-dir=~/.rvm/usr
但这没有帮助。
所以我尝试用普通的方式连接NET::HTTPS
并且能够连接到另一个网站,但不能连接到shopify。
>> require "net/https" #=> false
>> require "uri" #=> false
>> uri = URI.parse("https://google.com/") #=> #<URI::HTTPS:0x007fa27bb243f8 URL:https://google.com/>
>> http = Net::HTTP.new(uri.host, uri.port) #=> #<Net::HTTP google.com:443 open=false>
>> http.use_ssl = true #=> true
>> http.verify_mode = OpenSSL::SSL::VERIFY_NONE #=> 0
>> http.start { |agent| p agent.get(uri.path).read_body }
"<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe document has moved\n<A HREF=\"https://www.google.com/\">here</A>.\r\n</BODY></HTML>\r\n"
=> "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe document has moved\n<A HREF=\"https://www.google.com/\">here</A>.\r\n</BODY></HTML>\r\n"
>> uri = URI.parse("https://mysite.myshopify.com/admin/")
=> #<URI::HTTPS:0x007fa27d1f5e38 URL:https://mysite.myshopify.com/admin/>
>> http = Net::HTTP.new(uri.host, uri.port) #=> #<Net::HTTP mysite.myshopify.com:443 open=false>
>> http.use_ssl = true #=> true
>> http.verify_mode = OpenSSL::SSL::VERIFY_NONE #=> 0
>> http.start { |agent| p agent.get(uri.path).read_body }
Errno::ECONNRESET: Connection reset by peer - SSL_connect
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start'
from (irb):18
from /Users/zubin/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
所以这就排除了我的 ruby/openssl 设置。有什么想法导致 SSL_connect 错误吗?
最有可能的是,您的客户端正在尝试使用以下方式进行连接TLS 1.2
,最近的一项SSL/TLS
使用的协议HTTPS
。我们的负载平衡硬件存在一个已知问题TLS 1.2
,尽管直到我自己独立地偶然发现了这个错误之前我们才意识到这一点。
我已经让运营团队的其他成员意识到了这一点,我希望我们会尽快解决这个问题。在那之前,您可以使用
http.ssl_version = :TLSv1
强迫Ruby
to use TLS 1.0
反而。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)