gpt4 book ai didi

python - 名称错误 : global name 'send_from_directory' is not defined

转载 作者:行者123 更新时间:2023-11-28 19:33:16 25 4
gpt4 key购买 nike

<分区>

我正在使用 Flask 并尝试提供一个文件供用户下载。

我的代码看起来像这样:

@app.route('/downloads/<string:yt_id>')
def download_file(yt_id):

def hooks(data):
if data['status'] == 'finished':
filename = data['filename']

ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'progress_hooks': [hooks],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v='+yt_id])


return send_from_directory(".",
filename,
as_attachment=True)

我想上面代码唯一相关的部分是:

    return send_from_directory(".",
filename,
as_attachment=True)

这是我收到的错误消息:

NameError: global name 'send_from_directory' is not defined

我看过几个关于人们如何使用 send_from_directory 的例子,但我没有发现我所做的有什么不同。因此,我们将不胜感激任何帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com