【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()}")
相关推荐
无名小卒~≯42 分钟前
mybatis重复查询导致内存地址相同bug
bug·mybatis
测试人社区—84162 小时前
Mocking与Stubbing在单元测试中的正确使用
人工智能·git·单元测试·自动化·bug·postman
爆更小哇7 小时前
软件测试bug篇+因bug与开发产生争执该如何做
bug
2401_860494702 天前
React Native鸿蒙跨平台开发:error SyntaxError:Unterminated string constant.解决bug错误
javascript·react native·react.js·ecmascript·bug
天才测试猿3 天前
快速定位bug,编写测试用例
自动化测试·软件测试·功能测试·测试工具·职场和发展·测试用例·bug
福大大架构师每日一题4 天前
PyTorch v2.9.1 发布:重要 Bug 修复与性能优化详解
人工智能·pytorch·bug
黑臂麒麟4 天前
Electron&OpenHarmony 跨平台实战开发(bug):npm 安装 Electron 依赖常见错误排查
electron·npm·bug·openharmony
CIb0la4 天前
Complete Bug Bounty tool List for free
linux·运维·bug
欧恩意4 天前
【Viusal Studio】关于增量链接机制
汇编·windows·bug
Austindatabases4 天前
SQLite 开发中的数据库开发规范 --如何提升业务系统性能避免基础BUG
数据库·oracle·sqlite·bug·数据库开发