Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

browser - Upload file larger than MAX_CONTENT_LENGTH in Flask results connection reset

I'm trying to limit upload file size, I set app.config['MAX_CONTENT_LENGTH'] to the maximum value I want,

I used this code to display the error.

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

When using curl, the error displayed correctly. I checked using Firefox/Safari, in both I get browser error of connection dropped/reset.

Firefox

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.

Safari

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

server log in all of those requests

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

Why the error doesn't display correctly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's an issue related to Flask's development server, you needn't worry about it. Run the application with production server will solve this problem.

In this snippet that 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.

See update here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...