From f66e4d41c9a18e015afab3cb8923a12c602906ac Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Jul 2026 14:10:59 +0800 Subject: [PATCH] =?UTF-8?q?fix(deps):=20=E4=BF=AE=E5=A4=8D=20pyasn1=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=86=B2=E7=AA=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: - pyasn1>=0.5.0 移除了 pyasn1.compat.octets 模块 - python-jose==3.5.0 强制要求 pyasn1>=0.5.0 - 形成版本冲突,导致 pysnmp 无法导入 解决方案: - pyasn1==0.4.8 (保留 compat.octets 的版本) - pyasn1-modules==0.2.8 (配套版本) - python-jose[cryptography]==3.3.0 (兼容 pyasn1 0.4.8) 验证: - Python 3.10 & 3.11 均可正常导入 - FastAPI 应用可正常加载 (95 routes) --- PYTHON_3_10_COMPATIBILITY.md | 9 +++++++++ backend/requirements.txt | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/PYTHON_3_10_COMPATIBILITY.md b/PYTHON_3_10_COMPATIBILITY.md index 4efeda6..f20a1ea 100644 --- a/PYTHON_3_10_COMPATIBILITY.md +++ b/PYTHON_3_10_COMPATIBILITY.md @@ -30,6 +30,15 @@ from pysnmp.hlapi.asyncio import bulkCmd, getCmd, nextCmd ``` +#### pyasn1 版本冲突解决 +**问题**:`pyasn1>=0.5.0` 移除了 `pyasn1.compat.octets` 模块,导致 pysnmp 导入失败。 +同时 `python-jose==3.5.0` 强制要求 `pyasn1>=0.5.0`,形成版本冲突。 + +**解决方案**: +- `pyasn1==0.4.8` - 锁定到包含 compat.octets 的版本 +- `pyasn1-modules==0.2.8` - 配套版本 +- `python-jose[cryptography]==3.3.0` - 兼容 pyasn1 0.4.8 的版本 + ### 依赖版本要求 - `pysnmp-lextudio==5.0.31` - SNMP 协议兼容替代 - `typing-extensions>=4.5.0` - 提供额外的类型支持 diff --git a/backend/requirements.txt b/backend/requirements.txt index f0fd02a..1dbb442 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -13,11 +13,15 @@ alembic==1.13.1 # 注意: pysnmp 7.x 与 Python 3.10+/asyncio 存在兼容性问题 # 使用 lextudio 维护的分支(向后兼容,支持 Python 3.6+) pysnmp-lextudio==5.0.31 +# pyasn1 0.5.0+ 移除了 compat.octets 模块,与 pysnmp 不兼容 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 scapy==2.5.0 python-dotenv==1.0.1 passlib[bcrypt]==1.7.4 httpx==0.27.0 -python-jose[cryptography] +# python-jose 3.5.0 需要 pyasn1>=0.5.0,与 pysnmp 冲突 +python-jose[cryptography]==3.3.0 bcrypt==3.2.2 # typing-extensions 提供 Python 3.10+ 的向后兼容支持 typing-extensions>=4.5.0