因此,我正在调用一个API,即使我将超时设置为1000秒,它的超时时间在30秒之后也会保持超时,我的实现可能是错误的。
require 'HTTParty'
require 'json'
class Api
include HTTParty
default_timeout 1000
@@Json
def initialize(api_root_url, code)
response = HTTParty.get("#{api_root_url}/api/page/"+code)
@@Json = JSON.parse(response.body)
end
end错误
/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:146:in rbuf_fill‘from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2562:in rescue in rbuf_fill': Timeout::Error (Timeout::Error) from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:140:inreadline’from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2562:in read_status_line' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2551:inread_new‘from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1319:in transport_request' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:incatch‘from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1286:in block in transport_request' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in transport_request' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:inrequest’from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1286:inblock in transport_request' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:instart‘from。请求` rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1284:in‘
提前感谢
发布于 2013-08-16 23:54:33
请尝试设置default_timeout:
http://rdoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods#default_timeout-instance_method
https://stackoverflow.com/questions/18271931
复制相似问题