From 98c9e3b3756717771fd6521dbb2dbec206ec5fc5 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Mon, 28 Dec 2015 14:50:46 -0800 Subject: [PATCH] Catch sendfile failure from no file descriptor If the filelike response object has no `fileno` attribute, then skip trying to use sendfile rather than failing with an error. Close #1160 --- gunicorn/http/wsgi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index c537166ea..1d48467d1 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -355,6 +355,10 @@ def sendfile(self, respiter): try: fileno = respiter.filelike.fileno() + except AttributeError: + return False + + try: offset = os.lseek(fileno, 0, os.SEEK_CUR) if self.response_length is None: filesize = os.fstat(fileno).st_size