所以我正在调用一个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/rube/1.9.1/net/protocol.rb:146:在rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:140:in
rbuf_fill'中来自.rbenv/versions/1.9.3-p194/lib/rube/1.9.1/net/protocol.rb:122:in readuntil'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:132:in
readline'来自.rbenv/versions/1.9.3-p194/lib/rube/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:in
read_new'来自.rbenv/versions/1.9.3-p194/lib/rube/1.9.1/net:http.rb:1319:在block in transport_request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in
catch'中来自.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net:http.rb:1316:在transport_request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:in
请求中'从.rbenv/versions/1.9.3-p194/lib/rube/1.9.1/net:http.rb:1286:在block in request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in
启动'来自.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net:http.rb:1284:在"请求"中
提前感谢
尝试设置default_timeout
:
http://rdoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods#default_timeout-instance_method