From cec7056d72b21c0fe895e40b3eac1c5424813a6b Mon Sep 17 00:00:00 2001 From: cnbugs <717192502@qq.com> Date: Tue, 21 Jul 2026 13:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=AE=8C=E7=BE=8E?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=20Python=203.10=20=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=20PySNMP=20=E8=AF=A1=E5=BC=82=E7=9A=84=20(unknown=20l?= =?UTF-8?q?ocation)=20=E5=AF=BC=E5=85=A5=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nown-location%29-%E5%AF%BC%E5%85%A5%E6%8A%A5%E9%94%99.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/%E5%AE%8C%E7%BE%8E%E8%A7%A3%E5%86%B3-Python-3.10-%E7%8E%AF%E5%A2%83%E4%B8%8B-PySNMP-%E8%AF%A1%E5%BC%82%E7%9A%84-%28unknown-location%29-%E5%AF%BC%E5%85%A5%E6%8A%A5%E9%94%99.md b/%E5%AE%8C%E7%BE%8E%E8%A7%A3%E5%86%B3-Python-3.10-%E7%8E%AF%E5%A2%83%E4%B8%8B-PySNMP-%E8%AF%A1%E5%BC%82%E7%9A%84-%28unknown-location%29-%E5%AF%BC%E5%85%A5%E6%8A%A5%E9%94%99.md index eec6e03..0a24d0e 100644 --- a/%E5%AE%8C%E7%BE%8E%E8%A7%A3%E5%86%B3-Python-3.10-%E7%8E%AF%E5%A2%83%E4%B8%8B-PySNMP-%E8%AF%A1%E5%BC%82%E7%9A%84-%28unknown-location%29-%E5%AF%BC%E5%85%A5%E6%8A%A5%E9%94%99.md +++ b/%E5%AE%8C%E7%BE%8E%E8%A7%A3%E5%86%B3-Python-3.10-%E7%8E%AF%E5%A2%83%E4%B8%8B-PySNMP-%E8%AF%A1%E5%BC%82%E7%9A%84-%28unknown-location%29-%E5%AF%BC%E5%85%A5%E6%8A%A5%E9%94%99.md @@ -45,7 +45,8 @@ ImportError: cannot import name 'SnmpEngine' from 'pysnmp.hlapi' (unknown locati 完整的代码实现 在你的 snmp_service.py 文件最顶部(必须在所有 pysnmp 导入之前),加入以下代码: -`Python +``` +Python import collections import collections.abc import asyncio @@ -80,7 +81,8 @@ logger = logging.getLogger(__name__) class SNMPService: # 下面开始写你的业务逻辑... - pass` + pass + ``` 避坑总结 警惕 (unknown location): 在 Python 3.9+ 环境中看到这个错,不要死磕包路径,立刻去查是不是底层库用了被废弃的内置属性(如 collections 相关)。