title: gunicorn - AttributeError: 'function' object has no attribute 'read'
body: <p>I am attempting to create a docker image with flask, gunicorn, and nginx.
  This application downloads a zip file generated with io.BytesIO() returning a send_file() function.</p>
  <p>this is the function that generates the zip file:</p>
  <pre><code>def download_zip():
      result = decode_base64()
  
      zip_file_bytes_io = io.BytesIO()  # Create an in-memory zip file from the in-memory image file data.
  
      with ZipFile(zip_file_bytes_io, 'w') as zip_file:
          for image_name, bytes_stream in result:
              zip_file.writestr(str(image_name) + &quot;.jpg&quot;, base64.decodebytes(bytes_stream))
      zip_file_bytes_io.seek(0)
  
      return zip_file_bytes_io
  </code></pre>
  <p>This is the Flask function that downloads the file:
  @app.route('/download')</p>
  <pre><code>def download():
      zip_file = download_zip
      print(&quot;Zip File ready&quot;)
      # zip_file = None
      if not zip_file:
          return render_template(&quot;download.html&quot;)
      else:
          return send_file(zip_file, as_attachment=True, attachment_filename='archive.zip')
  </code></pre>
  <p>The file downloads ok when I use the Flask native server in development:</p>
  <pre><code>app.run(host='0.0.0.0', port=5000, debug=os.environ.get('DEBUG') == '1')
  </code></pre>
  <p>However, it returns <strong>AttributeError: 'function' object has no attribute 'read'</strong> when I use the gunicorn server.</p>
  <p>Here is the full error report:</p>
  <pre><code>[2022-07-20 06:12:11 +0000] [24] [ERROR] Error handling request /download
  web_1    | Traceback (most recent call last):
  web_1    |   File &quot;/usr/local/lib/python3.10/site-packages/gunicorn/workers/sync.py&quot;, line 136, in handle
  web_1    |     self.handle_request(listener, req, client, addr)
  web_1    |   File &quot;/usr/local/lib/python3.10/site-packages/gunicorn/workers/sync.py&quot;, line 182, in handle_request
  web_1    |     resp.write_file(respiter)
  web_1    |   File &quot;/usr/local/lib/python3.10/site-packages/gunicorn/http/wsgi.py&quot;, line 386, in write_file
  web_1    |     for item in respiter:
  web_1    |   File &quot;/usr/local/lib/python3.10/site-packages/gunicorn/http/wsgi.py&quot;, line 35, in __getitem__
  web_1    |     data = self.filelike.read(self.blksize)
  web_1    | AttributeError: 'function' object has no attribute 'read'
  proxy_1  | 192.168.128.1 - - [20/Jul/2022:06:12:11 +0000] &quot;GET /download HTTP/1.1&quot; 500 141 &quot;http://localhost/&quot; &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36&quot; &quot;-&quot;
  </code></pre>