8000 flask.send_file can't handle some attachment_filename with unicode characters · Issue #1 · crempp/flask · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
flask.send_file can't handle some attachment_filename with unicode characters  #1
Open
@crempp

Description

@crempp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0