Python bottle module causes “Error: 413 Request Entity Too Large”

↘锁芯ラ 提交于 2019-11-29 06:07:56

问题


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 part (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 part (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();

The first request prints:

100000

The second request prints:

...
<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>
....

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?


回答1:


You should be able to just

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

This appears to be the only way based on the source



来源:https://stackoverflow.com/questions/16865997/python-bottle-module-causes-error-413-request-entity-too-large

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!