mercredi 22 avril 2015

FLASK: Serving file to browser behind API proxy

When the user enteres the code below generates a data.csv file and serves it to the browser. It was perfectly on my localhost.

However, I have deployed it behind an API proxy, so that the user makes a call to which is internally transformed into

As a result, instead of serving data.csv to the browser as on localhost, it shows on the browser all the data. The view source-code feature shows exactly what data.csv should contain, but it is not being served as attachement. Any ideas?

from flask import make_response

@app.route('/', methods = ['GET'])
def get_file():

    alldata = []

    while len(new_data) > 0:
            new_data = api.timeline(max_id=oldest)
            oldest = alldata[-1].id - 1    

    outdata = ""
    for data in alldata:
            outdata += ",".join(data) + "\n"

    response = make_response(outdata)
    response.headers["Content-Disposition"] = "attachment; filename=data.csv"

    return response

if __name__ == '__main__': = app.config['HOST'], port = app.config['PORT'])

Aucun commentaire:

Enregistrer un commentaire