首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/indexsendjepp上的ValueError :对已关闭文件的I/O操作

/indexsendjepp上的ValueError :对已关闭文件的I/O操作
EN

Stack Overflow用户
提问于 2017-02-21 15:37:59
回答 1查看 253关注 0票数 1

我想上传'F:comic\picture\jepp‘中的zip文件。我使用以下代码:

代码语言:javascript
复制
def sendjepp(request):
    docuPath ='F:comic\picture\jepp'
    temp = tempfile.TemporaryFile()
    f = zipfile.ZipFile(temp, 'w', zipfile.ZIP_DEFLATED)
    for dirpath,dirnames,filenames in os.walk(docuPath):
          for filename in filenames:
              f.write(os.path.join(dirpath,filename))
    # f.close()
    wrapper = FileWrapper(temp)
    response = HttpResponse(wrapper, content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=test.zip'
    response['Content-Length'] = temp.tell()
    temp.seek(0)
    return response

我得到了这个错误:

EN

回答 1

Stack Overflow用户

发布于 2021-10-25 15:21:46

当我遇到这个问题时回答,这是我发现的唯一问题。

您需要使用StreamingHttpResponse (docs here)而不是HttpResponse

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42361264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档