V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ClericPy
V2EX  ›  Python

有谁遇到过 aiohttp Got more than 8190 bytes Headers 相关的错误了吗

  •  
  •   ClericPy ·
    ClericPy · 2021-03-17 23:26:19 +08:00 · 2017 次点击
    这是一个创建于 1133 天前的主题,其中的信息可能已经有所发展或是发生改变。

    复现方式

    Server Code

    import bottle
    
    app = bottle.Bottle()
    
    
    @app.get('/')
    def index():
        bottle.response.set_cookie("a" * 10000, "test")
        return 'ok'
    
    
    app.run()
    

    Client Code

    import asyncio
    from aiohttp import ClientSession
    
    
    async def main():
        async with ClientSession() as req:
            async with req.get('http://127.0.0.1:8080/') as r:
                print(await r.text())
    
    
    asyncio.run(main())
    

    报错就是

    aiohttp.client_exceptions.ClientResponseError: 400, message='Got more than 8190 bytes (10005) when reading request header field Set-Cookie.', url=URL('http://127.0.0.1:8080/')

    尝试

    简单的 patch 一个类的方法, 改掉默认值. 失败, 因为这是 C 实现的...

    https://github.com/aio-libs/aiohttp/search?q=max_field_size+&type=

    基本全是写死的常量默认值

    另:

    基本又是一个 aiohttp 独占的报错, 浏览器 / httpx / Requests 都没这问题.

    12 条回复    2021-03-22 20:48:18 +08:00
    Kobayashi
        1
    Kobayashi  
       2021-03-18 00:38:08 +08:00   ❤️ 1
    依赖的太深了,不好改,monkey patch 吧。

    https://pastebin.com/VrcZaj32
    https://pastebin.com/raw/VrcZaj32
    abersheeran
        2
    abersheeran  
       2021-03-18 14:12:34 +08:00
    httpx yes !
    ClericPy
        3
    ClericPy  
    OP
       2021-03-19 09:45:08 +08:00
    @abersheeran 之前选型 httpx 被 aiohttp 那些 C 的模块从性能上打败了, 现在我也被那些 C 里包的写死参数给打败了... 郁闷, 估计只能用 httpx 或者 Requests 整个备份 HTTP 请求模块了


    @Kobayashi 之前打 patch 一路不生效, 我还以为是我语法问题, 后来去源码里一看才发现各种 pyx xxx.c 火花带闪电, 感谢提供源码, 我试试看哈, 就喜欢这种人狠话不多直接 show me your code...
    ClericPy
        4
    ClericPy  
    OP
       2021-03-19 09:48:52 +08:00
    @Kobayashi 再次感谢... 我一开始打 Patch 位置不对, 打到 MultipartReader 上了似乎压根不是这里...
    abersheeran
        5
    abersheeran  
       2021-03-19 10:07:01 +08:00
    @ClericPy 不对吧。我记得 aiohttp 的客户端性能没比 httpx 好到哪儿去。也就服务端性能不错。
    ClericPy
        6
    ClericPy  
    OP
       2021-03-19 10:23:44 +08:00
    @abersheeran 之前特意测了客户端的性能, 打的是本地 127.0.0.1 的接口, 复用 Session 的时候并发一上去 aiohttp 比 httpx 快了一倍, 不过已经是前年做的实验了, 现在 httpx 有没有把 Cython 支持上还不确定


    @Kobayashi 呃, 找了台 windows 测试 ok, 在 Linux 上(Manjaro, Python3.9) 无效, 我继续找找什么问题
    ClericPy
        7
    ClericPy  
    OP
       2021-03-19 10:26:28 +08:00
    @Kobayashi windows 上是 py 文件, Linux 下 http_parser 安装以后编译带了 .so 和 .c 那些... 难怪之前死活打不上了
    Kobayashi
        8
    Kobayashi  
       2021-03-19 10:51:50 +08:00
    @ClericPy 确实是,那估计没得玩儿了。
    ClericPy
        9
    ClericPy  
    OP
       2021-03-19 10:56:15 +08:00
    @Kobayashi 找了半天官方 issue 里有提到, 然后三四年没新消息, 要不是 aiohttp 真的快, 早就换别的用了... 已经不少于 5 次遇到这种它独占的问题了, 别的库都没这种情况, 不过之前的都能打补丁解决, 这次的真就坑了
    abersheeran
        10
    abersheeran  
       2021-03-19 11:04:56 +08:00
    @ClericPy 你说测这个啊,那的确是 aiohttp 更快,毕竟有 C 加持。不过一般发请求的客户端速度瓶颈都在目标服务器啊。
    sujin190
        11
    sujin190  
       2021-03-22 11:41:56 +08:00
    8k 的 http 头还不够,你这是要往 http 头写啥。。
    ClericPy
        12
    ClericPy  
    OP
       2021-03-22 20:48:18 +08:00
    @sujin190 我是读... 看官方 Github 似乎服务端有办法覆盖这个参数, 客户端没辙...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5768 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:26 · PVG 14:26 · LAX 23:26 · JFK 02:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.