Browser – Upload a file larger than max_content_length in the Flask results connection reset

I am trying to limit the upload file size, I set app.config [‘MAX_CONTENT_LENGTH’] to the maximum value I want,

I use This code shows the error.

@app.errorhandler(413)
def request_entity_too_large(error):
return'File Too Large', 413

When using curl, the error is displayed correctly.
I checked using Firefox/Safari, and I got the browser connection loss/reset error.

Firefox

< p>

The connection was reset

The connection to the server was reset while the page was loading.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

Apple browser

Can't open the page
...server unexpectedly dropped the connection.. .

The server logs all these requests

192.168.1.1--[23/May/2015 15:50:34] "POST / HTTP/1.1 "413 -

Why can’t the error be displayed correctly?

This is a problem related to Flask’s development server, you don’t have to worry about it. Run on a production server The application will solve this problem.

In this snippet posted by Armin Ronacher, he said:

You might notice that if you start not accessing .form or .files on incoming POST requests, some browsers will honor this with a connection reset message. This can happen if you start rejecting uploads that are larger than a given size.

Some WSGI servers solve that problem for you, others do not. For instance the builtin Flask webserver is pretty dumb and will not attempt to fix this problem.

我I am trying to limit the upload file size, I set app.config [‘MAX_CONTENT_LENGTH’] to the maximum value I want,

I use this code to display the error.

< p>

@app.errorhandler(413)
def request_entity_too_large(error):
return'File Too Large', 413

When using curl, error The display is correct.
I checked using Firefox/Safari and I got the browser connection lost/reset error.

Firefox

The connection was reset

The connection to the server w as reset while the page was loading.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

Apple browser

Can't open the page
...server unexpectedly dropped the connection...

The server logs all these requests

192.168.1.1--[23/May/2015 15:50:34] "POST / HTTP/1.1" 413 -

Why can’t the error be displayed correctly?

This is a problem related to Flask’s development server, you don’t have to worry about it. Running the application with a production server will solve this problem.

In this snippet published by Armin Ronacher, he said:

You might notice that if you start not accessing .form or .files on incoming POST requests, some browsers will honor this with a connection reset message. This can happen if you start rejecting uploads that are larger than a given size.

Some WSGI servers solve that problem for you, others do not. For instance the builtin Flask webserver is pretty dumb and will not attempt to fix this problem.

Leave a Comment

Your email address will not be published.