Requests: Received response with content-encoding: gzip, but failed to decode it

Created on 3 Feb 2017  路  2Comments  路  Source: psf/requests

import requests

requests.get('http://gett.bike/')

This code raises the following exception:

ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.',
error('Error -3 while decompressing data: incorrect data check',))

Arch linux x64
requests==2.13.0
python=3.6.0

Most helpful comment

This seems like the server is returning data it claims is gzipped, but isn't, or is invalid somehow. curl agrees with this assessment, as you can see by doing curl -L --compressed http://gett.bike, which leads to:

curl: (23) Error while processing content unencoding: invalid block type

You can work around this for now by setting the Accept-Encoding header to identity:

import requests

requests.get('http://gett.bike/', headers={'Accept-Encoding': 'identity'})

But I strongly recommend you reach out to the server operator and get them to fix their server.

All 2 comments

This seems like the server is returning data it claims is gzipped, but isn't, or is invalid somehow. curl agrees with this assessment, as you can see by doing curl -L --compressed http://gett.bike, which leads to:

curl: (23) Error while processing content unencoding: invalid block type

You can work around this for now by setting the Accept-Encoding header to identity:

import requests

requests.get('http://gett.bike/', headers={'Accept-Encoding': 'identity'})

But I strongly recommend you reach out to the server operator and get them to fix their server.

I'm now receiving that same error. I've even switched hosting providers. Here's my output. Any ideas?

```Environment:

Request Method: GET
Request URL: https://sm8attachments.com/authenticate/callback/?code=1ace2d4df855a2b7e5fb6b1add0581102127cd5b&state=

Django Version: 2.1
Python Version: 3.6.6
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_celery_results',
'django.contrib.sites',
'user',
'account',
'attachment',
'webhook',
'authenticate',
'subscribe',
'home']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware')

Traceback:

File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/response.py" in _decode

  1. data = self._decoder.decompress(data)

File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/response.py" in decompress

  1. ret += self._obj.decompress(data)

During handling of the above exception (Error -3 while decompressing data: incorrect data check), another exception occurred:

File "/app/.heroku/python/lib/python3.6/site-packages/requests/models.py" in generate

  1. for chunk in self.raw.stream(chunk_size, decode_content=True):

File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/response.py" in stream

  1. data = self.read(amt=amt, decode_content=decode_content)

File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/response.py" in read

  1. data = self._decode(data, decode_content, flush_decoder)

File "/app/.heroku/python/lib/python3.6/site-packages/urllib3/response.py" in _decode

  1. "failed to decode it." % content_encoding, e)

During handling of the above exception (('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check',))), another exception occurred:

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

  1. response = wrapped_callback(request, callback_args, *callback_kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in view

  1. return self.dispatch(request, args, *kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch

  1. return handler(request, args, *kwargs)

File "/app/authenticate/views.py" in get

  1. for vendor in get_vendors(r['access_token']):

File "/app/authenticate/views.py" in get_vendors

  1. vendors = requests.get(url, headers=headers).json()

File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py" in get

  1. return request('get', url, params=params, **kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py" in request

  1. return session.request(method=method, url=url, **kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py" in request

  1. resp = self.send(prep, **send_kwargs)

File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py" in send

  1. r.content

File "/app/.heroku/python/lib/python3.6/site-packages/requests/models.py" in content

  1. self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''

File "/app/.heroku/python/lib/python3.6/site-packages/requests/models.py" in generate

  1. raise ContentDecodingError(e)

Exception Type: ContentDecodingError at /authenticate/callback/
Exception Value: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect data check',))```

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NoahCardoza picture NoahCardoza  路  4Comments

JimHokanson picture JimHokanson  路  3Comments

justlurking picture justlurking  路  3Comments

cnicodeme picture cnicodeme  路  3Comments

thadeusb picture thadeusb  路  3Comments