“文件结束到达”错误或使用HTTParty的Zlib :: BufError

时间:2015-06-19 21:25:41

标签: zlib httparty net-http

我遇到两个不同的错误 - 取决于我是在Ruby应用程序中使用Httparty还是从命令行使用它。

我尝试访问的网址:http://apiv2.ahrefs.com/?token= $ INSERT_VALID_AHREFS_API_TOKEN& from = backlinks& output = json& mode = domain& target = blog.ahrefs.com& limit = 1000 HTTP方法:GET

当我直接在bundle console中执行此操作时,我得到Zlib::BufError

HTTParty.get "http://apiv2.ahrefs.com/?token=$INSERT_VALID_AHREFS_API_TOKEN&from=backlinks_new_lost&output=json&mode=domain&target=blog.ahrefs.com&limit=1000"

Zlib::BufError: buffer error
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:357:in `finish'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:357:in `finish'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:262:in `ensure in inflater'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:262:in `inflater'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:274:in `read_body_0'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:201:in `read_body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:226:in `body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:163:in `reading_body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1414:in `block in transport_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1405:in `catch'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1405:in `transport_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1378:in `request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1371:in `block in request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:853:in `start'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1369:in `request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty/request.rb:98:in `perform'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:539:in `perform_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:475:in `get'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:577:in `get'
    from (irb):3
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/cli/console.rb:38:in `run'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/cli.rb:287:in `console'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/vendor/thor/command.rb:27:in `run'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/vendor/thor.rb:363:in `dispatch'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/vendor/thor/base.rb:440:in `start'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/cli.rb:9:in `start'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/bin/bundle:20:in `block in <top (required)>'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/bin/bundle:20:in `<top (required)>'
    from /Users/medic/.rbenv/versions/2.1.2/bin/bundle:23:in `load'
    from /Users/medic/.rbenv/versions/2.1.2/bin/bundle:23:in `<main>'irb(main):004:0> 

以下命令出现相同的错误: Net::HTTP.get(URI('http://apiv2.ahrefs.com/?token=$AHREFS_API_TOKEN&from=backlinks_new_lost&output=json&mode=domain&target=blog.ahrefs.com&limit=1000'))

当我从命令行执行此操作时:

httparty "http://apiv2.ahrefs.com/?token=$INSERT_VALID_AHREFS_API_TOKEN&from=backlinks_new_lost&output=json&mode=domain&target=blog.ahrefs.com&limit=1000"

/Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/protocol.rb:153:in `read_nonblock': end of file reached (EOFError)
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/protocol.rb:153:in `rbuf_fill'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/protocol.rb:104:in `read'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:316:in `ensure in read_chunked'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:316:in `read_chunked'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:276:in `block in read_body_0'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:269:in `inflater'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:274:in `read_body_0'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:201:in `read_body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:226:in `body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http/response.rb:163:in `reading_body'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1414:in `block in transport_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1405:in `catch'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1405:in `transport_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1378:in `request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1371:in `block in request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:853:in `start'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/http.rb:1369:in `request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty/request.rb:98:in `perform'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:539:in `perform_request'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:475:in `get'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/lib/httparty.rb:577:in `get'
    from /Users/medic/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/httparty-0.13.3/bin/httparty:90:in `<top (required)>'
    from /Users/medic/.rbenv/versions/2.1.2/bin/httparty:23:in `load'
    from /Users/medic/.rbenv/versions/2.1.2/bin/httparty:23:in `<main>'

当我将limit查询参数缩减为limit=10时,问题就消失了。

我的假设是,这是因为如果有足够的数据,服务器会返回分块响应。

我使用curl对网址进行了测试,结果毫不费力。这就是为什么我假设它是HTTParty中的一个问题

0 个答案:

没有答案