python web项目导出zip文件_python – Flask:如何向客户端发送动态生成的zipfile

我正在寻找一种方法将zipfile发送到客户端,该方法是从请求响应生成的.在此示例中,我将一个

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文件是空的,而烧瓶返回的错误是

Debugging middleware caught exception in streamed response at a point where response

headers were already sent

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值