【BUG】流式响应requests得到: ping - 和时间戳

前情提要

运行Langchain-Chatchat项目,使用自定义请求访问API Server流式输出

报错展示

bash 复制代码
b': ping - 2024-05-22 00:46:04.832520+00:00\r\n\r\n'

报错原因

这通常是由于 Server-Sent Events (SSE) 实现中使用的"心跳"机制,以确保连接保持活跃。一些 SSE 实现会定期发送 ping 消息,以防止连接超时或被关闭。

解决方案

1、降低sse_starlette版本为1.8.2

我之前用的是2.1.0,不想降低版本用第二个方法

2、EventSourceResponse函数中注释304~311行

bash 复制代码
            if self.ping_message_factory:
                assert isinstance(self.ping_message_factory, Callable)  # type: ignore  # https://github.com/python/mypy/issues/6864
            ping = (
                ServerSentEvent(comment=f"ping - {datetime.utcnow()}").encode()
                if self.ping_message_factory is None
                else ensure_bytes(self.ping_message_factory(), self.sep)
            )
            _log.debug(f"ping: {ping.decode()}")
相关推荐
hello_25020 小时前
bug排查思路大纲
bug
秃头小饼干20 小时前
关于Bug排查日记的技术文章大纲
bug
烧冻鸡翅QAQ20 小时前
测试中的Bug
bug·测试
云和数据.ChenGuang2 天前
java常见SSL bug解决方案
java·bug·ssl
cat_with_cat3 天前
测试:BUG篇
bug·测试
黑客飓风3 天前
Bug排查日记的技术
bug
Wiktok3 天前
[Wit]CnOCR模型训练全流程简化记录(包括排除BUG)
python·深度学习·bug
玄尺_0073 天前
bug:uniCloud报Business Failed, 参数有误retry invoke error
数据库·bug
程序猿阿伟3 天前
《云原生边缘与AI训练场景:2类高频隐蔽Bug的深度排查与架构修复》
人工智能·云原生·bug
夕阳UPdz3 天前
深入探索 Unity 错误排查过程:从“滚动条问题”到“鼠标悬浮异常”
bug