【发布时间】: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>'http://127.0.0.1:8008/test'</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