【问题标题】:Python bottle module causes "Error: 413 Request Entity Too Large"Python 瓶模块导致“错误:413 请求实体太大”
【发布时间】:2013-05-27 18:56:33
【问题描述】:

使用 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?

【问题讨论】:

  • 尝试将bottle.BaseRequest.MEMFILE_MAX 更改为大于102400 的值。
  • 我喜欢这个数字 102,400。太有意义了。
  • @vy32 实际上它比 looks 更随意。
  • 谢谢。这真的很有趣。 #TODO Should not be hard coded...。现在它不再是了!

标签: python http runtime-error bottle


【解决方案1】:

你应该可以

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

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

【讨论】:

  • 正好解决了我的问题!我怀疑我必须以某种方式访问​​MEMFILE_MAX 属性,但完全不确定。谢谢!
  • 另一个堆栈溢出用户拯救了我的一天 :) 只是为了方便:值以字节为单位,标准大小为 102400(也提到了链接中的来源)
  • 你先生,让我开心
猜你喜欢
  • 1970-01-01
  • 2016-02-01
  • 1970-01-01
  • 2016-11-24
  • 2016-07-16
  • 2017-03-05
  • 2014-12-30
  • 2014-12-23
相关资源
最近更新 更多