python result too large_Python瓶模块导致“错误:413请求实体太大”

使用Python的bottle模块时,当请求体大小超过bottle内部MEMFILE_MAX常量,会出现HTTP 413错误。文中给出了服务器和客户端代码示例,还提供了解决方案,即通过设置bottle.BaseRequest.MEMFILE_MAX来增加内部限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

...

Error: 413 Request Entity Too Large

Sorry, the requested URL 'http://127.0.0.1:8008/test'

caused an error:

Request to large

....

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?

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值