在Flask结果连接重置中上传大于MAX_CONTENT_LENGTH的文件 [英] Upload file larger than MAX_CONTENT_LENGTH in Flask results connection reset

查看:907
本文介绍了在Flask结果连接重置中上传大于MAX_CONTENT_LENGTH的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图限制上传文件的大小,我将app.config ['MAX_CONTENT_LENGTH']设置为所需的最大值,

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

使用curl时,错误显示正确。
我使用Firefox / Safari进行了检查,都出现了浏览器连接丢失/重置错误。

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 -

为什么无法正确显示错误? / p>

Why the error doesn't display correctly?

推荐答案

这是与Flask开发服务器相关的问题,您不必担心。在生产服务器上运行应用程序将解决此问题。

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.

这个片段由Armin Ronacher发布,他说:


您可能会注意到,如果您开始不在传入的POST上访问.form或.files,请求,某些浏览器会通过连接重置消息来兑现此请求。如果您开始拒绝大于给定大小的上载,则会发生这种情况。

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.

某些WSGI服务器可以为您解决该问题,而其他服务器则不能。例如,内置的Flask Web服务器非常笨拙,不会尝试解决此问题。

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.

这篇关于在Flask结果连接重置中上传大于MAX_CONTENT_LENGTH的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆