Getting an error attachment_filename does not exist in my docker environment

2024/10/5 15:34:34

Due to some reasons this particular code is not working in docker but it works fine in development environment. I am getting error "TypeError: send_file() got an unexpected keyword argument 'attachment_filename'" I have checked the official documents (https://tedboy.github.io/flask/generated/flask.send_file.html) and it says that we can use "attachment_filename" which exists. Not sure why I am getting this error. Plz help.

from flask import Flask, render_template, request, redirect, url_for, send_from_directory, request, jsonify, session, Response, send_file
from flask_login import LoginManager, login_user, logout_user, login_required, current_user
from pymongo import MongoClient
import urllib.parse
import bcrypt
import requests
import json
from datetime import datetime
import pandas as pd
from pathlib import Path
from flask import send_file
import io
import yaml@app.route('/download')
def dwnlnd()jsnx = session['mydata']df = pd.DataFrame.from_dict(jsnx)caldf = df.to_csv(index=False, header=True)buf_str = io.StringIO(caldf)buf_byt = io.BytesIO(buf_str.read().encode("utf-8"))return send_file(buf_byt,mimetype="text/csv",as_attachment=True,attachment_filename="data.csv")
Answer

This question comes up on search for this error so I'm adding a more explicit answer.
The explanation is that attachment_filename has been renamed download_name.

Quoting from the GitHub issue:

Old names for some send_file parameters have been removed. download_name replaces attachment_filename, max_age replaces cache_timeout, and etag replaces add_etags. Additionally, path replaces filename in send_from_directory.

https://en.xdnf.cn/q/70476.html

Related Q&A

How to check if a process with Command line argument is running using python

I would like to check if a script is running with a specific command line argument within a python script.For example I would like to check if:main.py testargIs running. Is there any way I can achieve …

cx_oracle and python 2.7 [duplicate]

This question already has answers here:Python module "cx_Oracle" module could not be found(4 answers)Closed 5 years ago.Im using python 2.7 and cx_oracle ( Windows x86 Installer (Oracle 10g, …

Inheritance in Python C++ extension

I have c++ library that need communicate with Python plugged in modules. Communication supposes implementing by Python some callback c++ interface. I have read already about writing extensions, but no …

exposing C++ class in Python ( only ET_DYN and ET_EXEC can be loaded)

I was looking at here to see how to expose c++ to Python. I have built Python deep learning code which uses boost-python to connect c++ and python and it is running ok, so my system has things for boos…

Migrations in mongoengine: InvalidId

I am working with mongoengine and trying to do a simple migration. I have a field which I would like to migrate from being a StringField to a ReferenceField to another Object. I planned on doing the …

Keras pretrain CNN with TimeDistributed

Here is my problem, I want to use one of the pretrain CNN network in a TimeDistributed layer. But I have some problem to implement it.Here is my model:def bnn_model(max_len):# sequence length and resne…

How to `pause`, and `resume` download work?

Usually, downloading a file from the server is something like this: fp = open(file, wb) req = urllib2.urlopen(url) for line in req:fp.write(line) fp.close()During downloading, the download process just…

AttributeError: module rest_framework.serializers has no attribute NullBooleanField

After upgrading djangorestframework from djangorestframework==3.13.1 to djangorestframework==3.14.0 the code from rest_framework.serializers import NullBooleanFieldThrowsAttributeError: module rest_fra…

Pandas convert dataframe values to column names

I want to use dataframe values as column names and simplify the dataframe.I tried df.stack() and then index.map({0[0]}_{0[1]}.format)Input_df(Got this df by doing a groupby):link price dateA 1 …

Pandas replace part of string with values from dictionary

I would like to replace the words in my dataframedf = pd.DataFrame({"Text": ["The quick brown fox jumps over the lazy dog"]})which match the keys in the following dictionarydic = {&…