【发布时间】:2019-11-23 22:31:32
【问题描述】:
我正在尝试使用烧瓶 restfull 和 send_file 在 json 对象中发送两个文件。
当我尝试在客户端访问 json 对象时,我收到此错误:
TypeError: Object of type 'Response' is not JSON serializable
这就是我在烧瓶应用中所做的:
class Download(Resource):
def get(self):
try:
return {"file1" : send_file('uploads/kode.png'), "file2" : send_file('uploads/kode.png')}, 200
except:
return {"message" : "File not found!"}, 404
如何返回 json 文件?
【问题讨论】:
-
什么是“json文件”?您究竟希望用户收到什么作为您问题中代码的响应?
-
如果我只用一个文件做同样的事情而不将 send_file() 包装在 {} 中,我可以在前端使用 java 脚本访问该文件。
标签: python json flask flask-restful