有时request.files在上传文件时在FLASK中不起作用

问题描述 投票:0回答:1

[我正在尝试使用下面的代码使用FLASK上传CSV文件,我正在尝试保存该文件的会话,以便以后使用。

if request.method=="POST":
    text=request.files['file']
    text_f=secure_filename(text.filename)
    text.save(os.path.join("",text_f))
    path=os.path.abspath(os.path.join("",text_f))
    with open(path) as tickets:
        ticket=pd.read_csv(tickets)
    tic_body=ticket['body']
    #session['tic_body']=tic_body

下面是HTML代码。

        <input type="file" class="form-control" id="images" name="file" multiple/>


        <input type="submit" class="btn btn-labeled btn-primary" value="stop">

使用此文件,我尝试上传文件时收到以下错误。

werkzeug.exceptions.HTTPException.wrap..newcls:400错误的请求:KeyError:'file'

注意:有时,当我不使用会话时,能够正确地加载文件。

python python-3.x flask python-requests flask-restful
1个回答
0
投票

嘿,你解决了这个问题

© www.soinside.com 2019 - 2024. All rights reserved.