Expected Behavior
Using flask.send_file should just work no matter what the attachment_filename string parameter contains including unicode characters.
# -*- coding: utf-8 -*- from flask import Flask, send_file app = Flask(__name__) @app.route("/") def hello(): fn = 'é.py' # alternate value # fn = '\xc3\xa9.py' return send_file('hello.py', as_attachment=True, attachment_filename=fn)
Actual Behavior
Exception is thrown. UnicodeDecodeError is not handled with a proper fallback.
Traceback (most recent call last): File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/remyroy/Projects/TestingFlask/hello.py", line 10, in hello return send_file('hello.py', as_attachment=True, attachment_filename=fn) File "/home/remyroy/VirtualEnvs/TestingFlask/local/lib/python2.7/site-packages/flask/helpers.py", line 567, in send_file attachment_filename = attachment_filename.encode('latin-1') UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Environment
- Python version: 2.7.12
- Flask version: 1.0.2
- Werkzeug version: 0.14.1