解决 aiohttp 独有的 “Got more than 8190 bytes (11984) when reading Header value is too long“ 错误

问题描述

在使用 aiohttp 时,你可能会遇到以下特有的错误:

aiohttp.client_exceptions.ClientResponseError: 400, message='Got more than 8190 bytes (11984) when reading Header value is too long.

这个错误是由于请求头的大小超过了 aiohttp 的默认限制 8190 字节。这是 aiohttp 独有的错误,其他 HTTP 客户端可能不会遇到类似问题。

初步解决方案

  • 修改 HeadersParser

我们可以尝试通过猴子补丁(monkey patching)修改 HeadersParser 来改变 aiohttp 的默认行为:

from aiohttp.http_parser import HeadersParser

def monkey_init(
    self,
    max_line_size: int = 8190,
    max_headers: int = 32768,
    max_field_size: int = 8190,
) -> None:
    self.max_line_size = max_line_size
    self.max_headers = max_headers
    self.max_field_size = 2 << 31

HeadersParser.__init__ &#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值