Python瓶模块导致“错误:413请求实体太大” [英] Python bottle module causes "Error: 413 Request Entity Too Large"
本文介绍了Python瓶模块导致“错误:413请求实体太大”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Python的模块 bottle
,我在发布正文大小> bottle
的请求时收到HTTP 413错误s内部 MEMFILE_MAX
常量。最小的工作示例如下所示。
Using Python's module bottle
, I'm getting HTTP 413 error when posting requests of body size > bottle
's internal MEMFILE_MAX
constant. Minimal working example is shown below.
服务器部分( 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>
....
我完全不知道如何增加瓶子
的内部限制。是否有任何简单的方法来增加限制,允许大小的请求,例如1 MB?
I have absolutely no idea how to increase the bottle
's internal limit. Is there any simple way to increase the limit, allowing requests of size, e.g., 1 MB?
推荐答案
你应该能够只需
import bottle
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 # (or whatever you want)
这似乎是基于 source
这篇关于Python瓶模块导致“错误:413请求实体太大”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文