Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gzipped 204 responses raises ContentEncodingError #609

Closed
C4ptainCrunch opened this issue Oct 30, 2015 · 11 comments
Closed

Gzipped 204 responses raises ContentEncodingError #609

C4ptainCrunch opened this issue Oct 30, 2015 · 11 comments
Labels

Comments

@C4ptainCrunch
Copy link

When querying an HTTP endpoint that returns a 204 with a content-encoding: gzip, aiohttp raises a aiohttp.errors.ContentEncodingError: 400, message='deflate'.
(Note that aiohttp claims it's a error 400 but the server sends a 204 : 127.0.0.1 - - [30/Oct/2015 13:01:37] "POST / HTTP/1.1" 204 -)

I made a small repo with a minimal example : https://github.com/C4ptainCrunch/aiohttp-204-gzip-bug

Here is the full stacktrace :

content-encoding: gzip

Traceback (most recent call last):
  File "client.py", line 14, in <module>
    fetch(url)
  File "/usr/lib64/python3.4/asyncio/base_events.py", line 316, in run_until_complete
    return future.result()
  File "/usr/lib64/python3.4/asyncio/futures.py", line 275, in result
    raise self._exception
  File "/usr/lib64/python3.4/asyncio/tasks.py", line 236, in _step
    result = coro.send(value)
  File "client.py", line 11, in fetch
    return (yield from response.release())
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/client_reqrep.py", line 648, in release
    chunk = yield from content.readany()
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/streams.py", line 472, in wrapper
    result = yield from func(self, *args, **kw)
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/streams.py", line 535, in readany
    return (yield from super().readany())
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/streams.py", line 265, in readany
    raise self._exception
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/parsers.py", line 181, in set_parser
    next(p)
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/protocol.py", line 312, in __call__
    out.feed_eof()
  File "/home/C4/sandbox/aiohttp/ve3/lib64/python3.4/site-packages/aiohttp/protocol.py", line 386, in feed_eof
    raise errors.ContentEncodingError('deflate')
aiohttp.errors.ContentEncodingError: 400, message='deflate'
@kxepal
Copy link
Member

kxepal commented Oct 30, 2015

Looks familiar #154

@carlcarl
Copy link
Contributor

carlcarl commented Nov 1, 2015

What the expected result should be?

@C4ptainCrunch
Copy link
Author

It should a least not declare an error 400 (it's not a "Bad request").
I think it should also not fail because of an empty response (especially with a 204 code)

Edit: Requests does not fail and returns a normal response object with an empty body

In [1]: import requests
In [2]: response = requests.post('http://localhost:5000')
In [3]: response
Out[3]: <Response [204]>
In [4]: response.text
Out[4]: u''

@asvetlov
Copy link
Member

asvetlov commented Nov 7, 2015

204 with body is forbidden combination from my perspective.
I have no clean idea what to do with malformed server response but perhaps we don't want to process it.

@C4ptainCrunch
Copy link
Author

I think you misunderstood, in my example, there is no body, the response seems well-formed :)

@C4ptainCrunch
Copy link
Author

Any updates on this ?

@mark-rushakoff
Copy link

I just ran into this same problem with aiohttp version 0.21.6 (and filed an upstream bug at influxdata/influxdb#6624).

In my use case, I'm expecting the 204 up front, and if I don't get a 204, I don't mind if the response is not compressed – so I can set the header Accept-Encoding: identity and aiohttp does not crash.

FWIW there is precedent for the client to gracefully accept a 204 with Content-Encoding: gzip in ladjs/superagent#898.

@khazhyk
Copy link

khazhyk commented Jun 16, 2016

Ditto, any empty response causes release() to raise if the content-encoding is gzip. This causes all HEAD requests to raise if the content encoding is gzip, which is quite annoying.

@khazhyk
Copy link

khazhyk commented Jun 16, 2016

Using the latest master code, I no longer get this error when using HEAD, fwiw.

@fafhrd91
Copy link
Member

fafhrd91 commented Feb 1, 2017

fixed in master

@fafhrd91 fafhrd91 closed this as completed Feb 1, 2017
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants