"End of file reached" error OR Zlib::BufError using HTTParty

980 views Asked by At

I am experiencing two different errors - depending on whether I use Httparty in my Ruby app or I use it from the command line.

URL I am trying to access: http://apiv2.ahrefs.com/?token=$INSERT_VALID_AHREFS_API_TOKEN&from=backlinks&output=json&mode=domain&target=blog.ahrefs.com&limit=1000 HTTP method: GET

When I do so directly in bundle console I get 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> 

Same error occurs for the following command: 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'))

When I do it from the command line:

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>'

The problem disappears when I reduce the limit query parameter to limit=10.

My assumption is that this is because the server returns a chunked response, if there is enough data.

I tested the URL with curl and it worked without a hitch. That's why I am assuming it is a problem in HTTParty

0

There are 0 answers