【发布时间】:2020-05-12 00:47:49
【问题描述】:
在 python 烧瓶中实现一个 rest API 时,我使用了几个选项来返回一个文件(任何类型),读取它并将它保存到请求的本地存储库,但遇到了多个错误,如下所示:
案例一:
def download_file():
return send_file('any_file.pdf')
r = requests.get(url = 'http://localhost:5000/download').read()
以错误响应响应对象没有属性读取/文本/内容
案例 2:
def download_file():
file = open('any_file.pdf','r').read()
return file
r = requests.get(url = 'http://localhost:5000/download')
已响应错误返回不接受此
所以我该怎么做,因为烧瓶不允许返回没有响应对象的文件,并且响应对象不可读并且不支持直接保存该文件。
【问题讨论】:
-
我想,你错过了方案 http:// 0.0.0.0:5000/download
-
是的,你是对的。现已编辑
标签: python flask response flask-restful sendfile