我正在为Flask应用程序编写后端,并且前端正在向我发送一个POST请求,其中包含multipart中的文件流。我有以下代码来读取文件:
from flask import request, jsonify, Flask
from flask.views import MethodView
import csv
app = Flask(__name__)
class ClassName(MethodView):
def get(self):
return "Data"
def post(self):
file_stream = request.files['file']
file_stream.read()
return file_stream
app.add_url_rule('/random', view_func = ClassName.as_view('random'))
if __name__ == '__main__':
app.run('0.0.0.0', port = 5001)
当我提交发布请求时,它会输出以下内容:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
我该怎么做才能解决这个问题?