【发布时间】:2014-12-18 06:17:52
【问题描述】:
我正在寻找一种向客户端发送从请求响应生成的压缩文件的方法。在此示例中,我将 JSON 字符串发送到 url,该 url 返回转换后的 JSON 字符串的 zip 文件。
@app.route('/sendZip', methods=['POST'])
def sendZip():
content = '{"type": "Point", "coordinates": [-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'})
但是我的zip文件是空的,flask返回的错误是
Debugging middleware caught exception in streamed response at a point where response
headers were already sent
【问题讨论】: