title: Download a file from a Flask-based Python server
body: <p>I'm trying to make work a code that I found at this URL: <a href="http://code.runnable.com/UiIdhKohv5JQAAB6/how-to-download-a-file-generated-on-the-fly-in-flask-for-python" rel="noreferrer">http://code.runnable.com/UiIdhKohv5JQAAB6/how-to-download-a-file-generated-on-the-fly-in-flask-for-python</a></p>
  
  <p>My goal is to be able to download a file on a web browser when the user access to a web service on my Flask-base Python server.</p>
  
  <p>So I wrote the following code:</p>
  
  <pre><code>@app.route("/api/downloadlogfile/&lt;path&gt;")
  def DownloadLogFile (path = None):
      if path is None:
          self.Error(400)
  
      try:
          with open(path, 'r') as f:
              response  = make_response(f.read())
          response.headers["Content-Disposition"] = "attachment; filename=%s" % path.split("/")[2]
  
          return response
      except Exception as e:
          self.log.exception(e)
          self.Error(400)
  </code></pre>
  
  <p>But this code doesn't seem to work. Indeed I get an error that I didn't manage to fix:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\gevent\pywsgi.py", line 508, in handle_one_response
  self.run_application()
  File "C:\Python27\lib\site-packages\geventwebsocket\handler.py", line 88, in run_application
  return super(WebSocketHandler, self).run_application()
  File "C:\Python27\lib\site-packages\gevent\pywsgi.py", line 495, in run_application
  self.process_result()
  File "C:\Python27\lib\site-packages\gevent\pywsgi.py", line 484, in process_result
  for data in self.result:
  File "C:\Python27\lib\site-packages\werkzeug\wsgi.py", line 703, in __next__
  return self._next()
  File "C:\Python27\lib\site-packages\werkzeug\wrappers.py", line 81, in _iter_encoded
  for item in iterable:
  TypeError: 'Response' object is not iterable
  </code></pre>
  
  <p>I update my Flask and Werkzeug package to the last version but without success.</p>
  
  <p>If anybody have an idea it would be great.</p>
  
  <p>Thanks in advance</p>