Python瓶模块导致 "Error: 413 Request Entity Too Large"

标签 python http bottle

使用 Python 的模块 bottle,我在发布正文大小的请求时遇到 HTTP 413 错误 > bottle 的内部 MEMFILE_MAX 常量。最小的工作示例如下所示。

服务器部分(server.py):

from bottle import *

@post('/test')
def test():
    return str(len(request.forms['foo']));

def main():
    run(port=8008);

if __name__ == '__main__':
    main();

客户端部分(client.py):

import requests

def main():
    url = 'http://127.0.0.1:8008/test';

    r = requests.post(url, data={ 'foo' : 100000 * 'a' });
    print(r.text);

    r = requests.post(url, data={ 'foo' : 200000 * 'a' });
    print(r.text);

if __name__ == '__main__':
    main();

第一个请求打印:

100000

第二个请求打印:

...
<body>
    <h1>Error: 413 Request Entity Too Large</h1>
    <p>Sorry, the requested URL <tt>&#039;http://127.0.0.1:8008/test&#039;</tt>
       caused an error:</p>
    <pre>Request to large</pre>
</body>
....

我完全不知道如何增加 bottle 的内部限制。有没有简单的方法来增加限制,允许大小的请求,例如 1 MB?

最佳答案

你应该可以

import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 # (or whatever you want)

这似乎是基于 source 的唯一方法

关于Python瓶模块导致 "Error: 413 Request Entity Too Large",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16865997/

相关文章:

python - 如何使用 __import__ 导入 *

python - Virtualenv 无法运行

python - 在具有条件增量的 pandas 数据框上使用 cumcount

android - Android 上的非阻塞 HTTP GET 查询

http - 防止 Mule 添加默认内容类型

python - 在 matplotlib 中动态更新条形图

angularjs - 加载完成后触发回调

python - 如何处理 Python Bottle 和 Apache .htaccess 中的 URL 重新路由?

python - 当调用相同的端点时,带有 CherryPy 的 Bottle 不会表现为多线程

python - 在 openshift 上的 Bottle.py 应用程序中加载静态文件