【问题标题】:module 'requests' has no attribute 'files'模块“请求”没有属性“文件”
【发布时间】:2019-12-20 23:15:58
【问题描述】:

运行脚本出现以下错误:

AttributeError: module 'requests' has no attribute 'files'

代码如下:

import requests

app = Flask(__name__)

@app.route('/api/test/', methods=['POST'])
def test(): 
    filesReceived = requests.files['file']

【问题讨论】:

标签: flask python-requests


【解决方案1】:

我从您的代码中了解到,您正在尝试获取请求收到的文件,对吗?

如果这是你想要的,那么你使用了错误的导入。

Requests 是 python 的 http 库。

如果要在请求中发送文件,需要使用request from flask

所以你的代码会是这样的:

from flask import request

app = Flask(__name__)

@app.route('/api/test/', methods=['POST'])
def test(): 
    filesReceived = request.files['file']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多