Skip to content
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 doesn't allow StringIO #3435

Merged
merged 1 commit into from
Nov 19, 2019
Merged

send_file doesn't allow StringIO #3435

merged 1 commit into from
Nov 19, 2019

Conversation

davidism
Copy link
Member

fixes #3358

Due to the way send_file works, passing a text mode file-like object, such as io.StringIO in Python 3, would respond with 200 OK and an empty file, while printing a traceback to the terminal. Even in Python 2, this only worked by accident, and would probably fail if given a StringIO.StringIO object with Unicode data that did not encode with the system encoding. It appears send_file was only intended to work with binary mode data.

Now, if the object is an instance of io.TextIOBase it raises a ValueError. This doesn't help for file-like objects that don't use the io ABCs (including Python 2), but it should cover most cases.

@davidism davidism added this to the 2.0.0 milestone Nov 19, 2019
@davidism davidism merged commit d49cfb3 into master Nov 19, 2019
@davidism davidism deleted the send-file-text branch November 19, 2019 17:08
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flask.send_file incorrectly sends blank files
1 participant