Browser 在烧瓶结果连接重置中上载大于最大内容长度的文件
我试图限制上传文件的大小,我将app.config['MAX\u CONTENT\u LENGTH']设置为我想要的最大值 我使用此代码来显示错误Browser 在烧瓶结果连接重置中上载大于最大内容长度的文件,browser,flask,Browser,Flask,我试图限制上传文件的大小,我将app.config['MAX\u CONTENT\u LENGTH']设置为我想要的最大值 我使用此代码来显示错误 @app.errorhandler(413) def request_entity_too_large(error): return 'File Too Large', 413 使用curl时,错误将正确显示。 我使用Firefox/Safari进行了检查,在这两种情况下,我都出现了连接断开/重置的浏览器错误 火狐 The connecti
@app.errorhandler(413)
def request_entity_too_large(error):
return 'File Too Large', 413
使用curl时,错误将正确显示。
我使用Firefox/Safari进行了检查,在这两种情况下,我都出现了连接断开/重置的浏览器错误
火狐
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.
狩猎
Can't open the page
...server unexpectedly dropped the connection...
服务器登录所有这些请求
192.168.1.1 - - [23/May/2015 15:50:34] "POST / HTTP/1.1" 413 -
为什么错误不能正确显示?这是一个与Flask的开发服务器相关的问题,您不必担心。使用生产服务器运行应用程序将解决此问题 在Armin Ronacher的帖子中,他说: 您可能会注意到,如果您在收到POST请求时开始不访问.form或.files,某些浏览器将通过连接重置消息来实现这一点。如果您开始拒绝大于给定大小的上载,则可能会发生这种情况 一些WSGI服务器为您解决了这个问题,其他的则没有。例如,内置Flask Web服务器相当愚蠢,不会尝试解决此问题
请参阅更新。Grey Li的回答解释了问题发生的原因 但我们仍然可以通过处理程序
RequestEntityTooLarge
来修复它,该处理程序是在Flask中中止(413)之前由werkzeug
引发的
from werkzeug.exceptions import RequestEntityTooLarge
@app.errorhandler(413)
@app.errorhandler(RequestEntityTooLarge)
def app_handle_413(e):
return 'File Too Large', 413
我认为这就是flask dev服务器的问题所在。你是如何运行你的应用程序的?