Rails - 考拉/法拉第宝石执行过期错误

时间:2017-09-19 06:08:49

标签: ruby-on-rails ruby ruby-on-rails-3 koala faraday

我正在使用Koala gem(v2.2)和Faraday(0.9.2)的rails应用程序。似乎很多facebook请求都是错误的,需要执行,我不知道为什么。这是一个堆栈跟踪。我将非常感谢有关如何解决此问题的帮助,

以下是代码段,它在oauth.get_app_access_token或app_graph.debug_token

上失败
oauth = Koala::Facebook::OAuth.new(Rails.application.config.facebook_app_id,
                                   Rails.application.config.facebook_app_secret,
                                   nil)

app_access_token = oauth.get_app_access_token # fails here
app_graph = Koala::Facebook::API.new(app_access_token)
token_info = app_graph.debug_token(atoken) # or fails here

这是错误:

ERROR: execution expired 
 /usr/lib/ruby/1.9.2/net/http.rb:644:in `initialize' 
 /usr/lib/ruby/1.9.2/net/http.rb:644:in `open' 
 /usr/lib/ruby/1.9.2/net/http.rb:644:in `block in connect' 
 /usr/lib/ruby/1.9.2/net/http.rb:644:in `connect' 
 /usr/lib/ruby/1.9.2/net/http.rb:637:in `do_start' 
 /usr/lib/ruby/1.9.2/net/http.rb:626:in `start' 
 /usr/lib/ruby/1.9.2/net/http.rb:1168:in `request' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:82:in `perform_request' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:40:in `block in call' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:87:in `with_net_http_connection' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:32:in `call' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb:15:in `call' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/request/multipart.rb:14:in `call' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request' 
 /usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/connection.rb:177:in `post' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala/http_service.rb:113:in `make_request' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala.rb:64:in `make_request' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala/oauth.rb:306:in `fetch_token_string' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala/oauth.rb:258:in `get_token_from_server' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala/oauth.rb:189:in `get_app_access_token_info' 
 /usr/lib/ruby/gems/1.9.2/gems/koala-2.2.0/lib/koala/oauth.rb:199:in `get_app_access_token' 

1 个答案:

答案 0 :(得分:1)

这是执行过期的/lib/faraday/adapter/net_http.rb:82:in 'perform_request' method

  def perform_request(http, env)
    if :get == env[:method] and !env[:body]
      # prefer `get` to `request` because the former handles gzip (ruby 1.9)
      http.get env[:url].request_uri, env[:request_headers]
    else
      # In your case you execture http.request
      http.request create_request(env)
    end
  end

这是Ruby文档Net::HTTP.request方法,我强调

  

返回HTTPResponse对象。

这是方法中的res,将基于Net::HTTPResponse ruby class

另外,我会关注request是如何制作的,因为我认为某些参数传递不正确,这就是响应需要这么长时间的原因。因此,我们应该关注请求正文,标题和所有其他信息。

# File net/http.rb, line 1421
def request(req, body = nil, &block)  # :yield: +response+
  unless started?
    start {
      req['connection'] ||= 'close'
      return request(req, body, &block)
    }
  end
  if proxy_user()
    req.proxy_basic_auth proxy_user(), proxy_pass() unless use_ssl?
  end
  req.set_body_internal body
  res = transport_request(req, &block)
  if sspi_auth?(res)
    sspi_auth(req)
    res = transport_request(req, &block)
  end
  res
end

那么在生产服务器日志中打印一些额外的日志信息呢,你可以打开这些文件/usr/lib/ruby/1.9.2/net/http.rb:1168:in 'request'/usr/lib/ruby/gems/1.9.2/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:82:in 'perform_request',在一些应输出的变量上写一些puts语句你的生产日志。

您还需要确保将rails app日志配置为打印它们。