Fix utils.is_fileobj for streaming responses from requests #805

Closed
davisp opened this Issue Jun 26, 2014 · 2 comments

Projects

None yet

3 participants

@davisp
Collaborator
davisp commented Jun 26, 2014

Turns out that the utils.is_fileobj breaks for streamed responses from the requests library due to how we check for a fileno() function and the exception raised by urllib3.

https://github.com/benoitc/gunicorn/blob/19.0/gunicorn/util.py#L511-L521
https://github.com/kennethreitz/requests/blob/v2.3.0/requests/packages/urllib3/response.py#L294-L301

Obvious fix is to add the IOError type to the exception list. PR to follow shortly.

@davisp davisp added the Bug label Jun 26, 2014
@davisp davisp added a commit that referenced this issue Jun 26, 2014
@davisp davisp Fix check for file-like objects
The `is_fileobject()` function in utils.py would break when the respones
was a wrapped `HTTPResponse`'s `raw` attribute. This just adds the
`IOError` exception type to the `is_fileobject()` function so that the
response can be streamed normally.

Fixes #805
fc364cc
@tilgovi tilgovi closed this in #806 Jun 26, 2014
@fmarczin

This bug can still be triggered by file-like objects which wrap objects without a .fileno() method. This happened to me in combination with pyfilesystem (https://github.com/PyFilesystem/pyfilesystem/blob/master/fs/iotools.py#L31).

The simplest fix would be to add AttributeError to the list of exceptions, just like in the commit above (fc364cc).

@tilgovi
Collaborator
tilgovi commented Nov 25, 2015

@fmarczin this code isn't used anymore on master as of 6b92575. If you could reproduce problems before and can check again on master that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment