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 相关)。