2012-09-15 36 views
4

我無法使用shopify_api gem訪問Shopify API。使用rubygem訪問Shopify API時出現SSL_connect錯誤

這裏發生了什麼:

>> 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的綁定問題,我安裝了OpenSSL與RVM並重新安裝紅寶石:

rvm pkg install openssl 
rvm reinstall 1.9.3-p194 --with-openssl-dir=~/.rvm/usr 

但是這並沒有幫助。

所以我嘗試用純ol'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錯誤?

+0

你還有這個問題嗎?你試圖連接到什麼商店,以便我們可以查看它。 –

+0

是的,仍然有這個問題。商店是隱藏的。謝謝約翰。 – Zubin

+0

這個問題一直困擾着那些使用Ubuntu(12.04)和Shopify相當長時間的人。請看看這些帖子: - http://stackoverflow.com/questions/12222580/shopify-creating-session-for-private-app - http://stackoverflow.com/questions/11267856/shopify-ubuntu -12-04lts-faraday-issue-ok-to-use-older-openssl 後者有某種「解決方案」,但不要屏住呼吸。 我不知道究竟是什麼造成了這種情況,但在我每天使用的衆多SSL端點中,Shopify是唯一存在此問題的人。 :( –

回答

7

最有可能的是,您的客戶正嘗試使用TLS 1.2連接,HTTPS中使用的最近的SSL/TLS協議之一。我們的負載平衡硬件有一個TLS 1.2已知的問題,雖然我沒有意識到它,直到我獨立地偶然發現了這個錯誤。

我已讓運營團隊的其他成員意識到了這一點,我希望我們會盡快解決此問題。在那之前,你可以使用

http.ssl_version = :TLSv1

強制Ruby使用TLS 1.0代替。

相關問題