0
我有以下flak_restful文件將csv文件返回給用戶,但出現以下錯誤。flask_restful無法返回文件
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'Response' is not JSON serializable
import flask
from flask import request
from flask_restful import Resource
class MyAPIRes(Resource):
@classmethod
def get(cls):
csv = '1,2,3\n4,5,6\n'
response = flask.make_response(csv)
response.headers['content-type'] = 'application/octet-stream'
return response, 200