-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
send_file: latin-1 encoding not compatible with gunicorn #2766
Comments
Headers are Latin-1. Gunicorn only allowing ASCII is incorrect. |
I know, headers should be encoded using latin-1, but I think it's not uncommon to use flask + gunicorn and looking at the closed issue from some time ago, it's not like they will change soon. However, I will open a new issue in the gunicorn bugtracker, as it's really a gunicorn issue. |
@davidism that's not true according the updated spec 7230:
Anyway it used to work with previous versions of flask. What changed since? |
|
@benoitc I based the change on the Unicode section of PEP 3333:
Werkzeug encodes with Latin-1 in many other places, including the encoding dance, so I'm not sure why it didn't cause issues before. The wsgiref server uses Latin-1 / ISO-8859-1 as well. |
Can I get an example of a filename that caused Gunicorn to raise an error? I changed Lines 641 to 649 in d22491a
Here's the code for the filename header (I replaced Lines 566 to 577 in d22491a
|
The following fails with Gunicorn: from flask import Flask, send_file
app = Flask(__name__)
@app.route('/')
def index():
return send_file('example.py', as_attachment=True, attachment_filename='pingüino.txt')
The filename is encodable as Latin-1, so it's passed through as-is. If it had UTF-8 characters, it would trigger the |
With the latest release (flask 1.0.0), unicode attachement filenames are allowed by flask.
I was waiting for this change and it seems to work great using the builtin dev server. However, gunicorn on the production server does not support
latin-1
encoding for the headers and only supportsascii
.Originaly flask also opted for ASCII encoding, however commit 336d6a4 changed this and since then
latin-1
is used.What was the rational to switch to
latin-1
? I know, officially it's allowed, however gunicorn decided to only support ASCII: (see related issue)Is there a change that flask also switches back to ASCII?
Related Issues:
The text was updated successfully, but these errors were encountered: