title: How to send a dynamically generate zipfile to the client
body: <p>I am looking for a way to send a zipfile to the client that is generated from a requests response. In this example, I send a JSON string to a URL which returns a zip file of the converted JSON string.</p>
  <pre><code>@app.route('/sendZip', methods=['POST'])
  def sendZip():
      content = '{&quot;type&quot;: &quot;Point&quot;, &quot;coordinates&quot;: [-105.01621, 39.57422]}'
      data = {'json' : content}
      r = requests.post('http://ogre.adc4gis.com/convertJson', data = data)
      if r.status_code == 200:
          zipDoc = zipfile.ZipFile(io.BytesIO(r.content))
          return Response(zipDoc,
                  mimetype='application/zip',
                  headers={'Content-Disposition':'attachment;filename=zones.zip'})
  </code></pre>
  <p>But my zip file is empty and the error returned by flask is</p>
  <pre><code>Debugging middleware caught exception in streamed response at a point where response 
  headers were already sent
  </code></pre>