PySNMP 错误:pysnmp.smi.error.SmiError
我正在 Windows XP 机器上运行 Python 程序。当我运行该程序时,出现以下错误:
File "C:\Python27\lib\pysnmp\smi\builder.pyt, line 230, in loadModules...
pysnmp.smi.error.SmiError: MIB file "SNMPv2-MIB.py[co]" not found in search path
文件 SNMPv2-MIB.py 当前位于 C:\Python27\Lib\pysnmp\smi\mibs 中。有谁知道我该如何解决这个问题?
I am running a Python program on a Windows XP machine. When I run the program, I get the following error:
File "C:\Python27\lib\pysnmp\smi\builder.pyt, line 230, in loadModules...
pysnmp.smi.error.SmiError: MIB file "SNMPv2-MIB.py[co]" not found in search path
The file SNMPv2-MIB.py is currently located in C:\Python27\Lib\pysnmp\smi\mibs
. Does anyone know how I can solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(5)
我遇到了同样的问题(使用 pysnmp-4.2.5)。我使用以下方法生成了自己的 MIB python 文件:
build-pysnmp-mib -o IF-MIB.py /usr/share/mibs/ietf/IF-MIB
在 RHEL6 上(build-pysnmp-mib
不适用于 RHEL5,因为它需要 libsmi 版本 > 0.4.5,而 RHEL5 只有此版本,而 RHEL6 有 0.4。 8).
然后我将生成的文件 IF-MIB.py 复制到 pysnmp 的其他 python MIB 文件所在的目录中,(/.../site-packages/pysnmp/smi/mibs/
)
我刚刚遇到了同样的问题。我为其提交了一个错误并包含了一个补丁:
https://sourceforge.net/tracker/?func =detail&aid=3204704&group_id=14735&atid=114735
正如 Sivakumar 所说,失败的原因是 pysnmp 正在寻找带有 .pyc 或 .pyw 扩展名的 MIB。 pysnmp 从 imp.get_suffixes() 获取这些扩展。根据 pysnmp 处理从此函数返回的扩展名的方式,.pyw 条目将覆盖 .py 条目。我提出的修复将简单地忽略 .pyw 扩展名。
如果您从 .egg 安装该库,它应该可以正常工作,因为 .egg 包含已编译的 (pyc) MIB。
您无法加载 MIB 文件。
您可以检查一下吗:
>>> print builder.MibBuilder().getMibPath()
通常这应该没问题,因为 mib 实例应该位于
pysnmp/smi/mibs/instances
builder.py 中引发错误的代码
if not self.__modSeen.has_key(modName):
raise error.SmiError(
'MIB file \"%s\" not found in search path' % (modName and modName + ".py[co]")
)
中。通常这应该通过在调用 loadModules 之前在 mibBuilder 实例上调用 setMibPath 来解决。
由于您获得的路径
C:\Python27\lib\pysnmp\smi\mibs\instances,
C:\Python27\lib\pysnmp\smi\mibs,
C:\Python27\lib\pysnmp_mibs
为什么不将文件移动到这些目录之一?
它当前所在的位置
- C:\Python27\Lib\pysnmp\smi\mibs
不在您通过 builder.MibBuilder().getMibPath() 获得的路径中
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
今天我也面临同样的问题。 mibs路径设置正确。在调试模式下运行 pysnmp 时,我发现它需要 SNMPv2-MIB.pyc 或 .pyw 文件。
由于我已从源代码中解压缩 pysnmp 并使用它,因此 mib 模块的相应 pyc 文件在该文件夹结构中不可用。我还没有尝试编译 pysnmp-4.1.13a\pysnmp\smi\mibs\instances 或 pysnmp-4.1.13a\pysnmp\smi\mibs 中可用的相应 .py 文件,而是使用 easyinstall 脚本来下载 pysnmp 模块。
有了egg文件,现在这个问题就不会出现了。
谢谢
西瓦库马尔
Today i too face this same issue. The mibs path is correctly set. While running the pysnmp in debugging mode, i am able to found that it is expecting a SNMPv2-MIB.pyc or .pyw file.
Since i have unzipped the pysnmp from source and using it, the corresponding pyc file for the mib module is not available in that folder structure. I havent tried compiling the corresponding .py files available in the pysnmp-4.1.13a\pysnmp\smi\mibs\instances or pysnmp-4.1.13a\pysnmp\smi\mibs, instead i used the easyinstall script to download the pysnmp module.
With the egg file, now the issue is not coming.
Thanks
Sivakumar