Faraday: Zlib::DataError on Get request

Created on 16 Feb 2012  ·  9Comments  ·  Source: lostisland/faraday

I am seeing a couple of urls which when requested result in an error 'Zlib::DataError: unknown compression method'

/faraday/adapter/net_http.rb:59:in call' /faraday/request/url_encoded.rb:14:incall'
/faraday/connection.rb:215:in run_request' /faraday/connection.rb:88:inget'
/faraday-a1c2dcf1c5c0/lib/faraday.rb:24:in `method_missing'

Example:
Faraday.get('http://www.imaginativeuniversal.com/blog/post/2012/02/14/Why-the-Kinect-for-Windows-Sensor-Costs-2424999.aspx')

I have tested on 0.7.6 and 0.8.RC2 on Ruby 1.9.3.

I also tested HTTParty on the same url and it appear to work...but I have not dug much further.

Thanks,
Scott

Most helpful comment

The server is sending the response using an unsupported compression method. Seems like it's the server's fault.

You can try working around it by setting a request header:

"accept-encoding" => "none"

Not sure if this will work. You can also use another adapter, such as Typhoeus.

All 9 comments

Looking into the source on net_http.rb and comparing it to HTTParty:

  • Faraday uses .get with a comment about using get instead of request because Ruby 1.9 handles gzip.
  • HTTParty is using .get and handing compression/deflating on it's own.

It looks like the bug is actually in Ruby. Here is a cleaner sample:

require 'net/https'

url = "http://www.imaginativeuniversal.com/blog/post/2012/02/14/Why-the-Kinect-for-Windows-Sensor-Costs-2424999.aspx"
uri = URI.parse(url)

http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

http.request(request).code #ok
http.get(request).code #fails

Net::HTTP#get isn't meant to receive a request object, it expects a path and (optionally) headers. It then builds its own request. See http://rubydoc.info/stdlib/net/1.9.2/Net/HTTP#get-instance_method

The server is sending the response using an unsupported compression method. Seems like it's the server's fault.

You can try working around it by setting a request header:

"accept-encoding" => "none"

Not sure if this will work. You can also use another adapter, such as Typhoeus.

It's a ruby bug.

url = "http://www.imaginativeuniversal.com/blog/post/2012/02/14/Why-the-Kinect-for-Windows-Sensor-Costs-2424999.aspx"
uri = URI.parse(url)

Net::HTTP.start(uri.host, uri.port) do |http|
  response = http.get(uri.request_uri)
  p response.body[0,100]
end

Getting:

net/http.rb:1035:in `inflate': unknown compression method (Zlib::DataError)

@mislav setting "accept-encoding" => "none" fixed the zlib error I was fighting. Thanks.

Sorry if this is obvious but how do I do this exactly?

@roryc89 When you're constructing a connection object:

Faraday.new headers: { accept_encoding: 'none' } do |conn|
  # ...
end

Or per-request:

conn.get '/foo/bar' do |req|
  req.headers[:accept_encoding] = 'none'
end

@mislav setting "accept-encoding" => "none" fixed the zlib error for me too, thanks! 👍

This worked for me too, Thanks guys!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuinnWilton picture QuinnWilton  ·  4Comments

mattmill30 picture mattmill30  ·  4Comments

subvertallchris picture subvertallchris  ·  5Comments

luizkowalski picture luizkowalski  ·  3Comments

mokolabs picture mokolabs  ·  3Comments