PySNMP 错误:pysnmp.smi.error.SmiError

发布于 2024-09-20 00:06:31 字数 315 浏览 3 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

謸气贵蔟 2024-09-27 00:06:37

今天我也面临同样的问题。 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

北凤男飞 2024-09-27 00:06:36

我遇到了同样的问题(使用 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/)

I ran into the same issue (with pysnmp-4.2.5). I generated my own MIB python file using:

build-pysnmp-mib -o IF-MIB.py /usr/share/mibs/ietf/IF-MIB

on RHEL6 (build-pysnmp-mib does not work on RHEL5 as it requires libsmi version > 0.4.5 and RHEL5 just has this version while RHEL6 has 0.4.8).

Then I copied the generated file IF-MIB.py into the directory where the other python MIB files of pysnmp are located, (/.../site-packages/pysnmp/smi/mibs/)

天生の放荡 2024-09-27 00:06:35

我刚刚遇到了同样的问题。我为其提交了一个错误并包含了一个补丁:
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。

I just ran into the same issue. I filed a bug for it and included a patch:
https://sourceforge.net/tracker/?func=detail&aid=3204704&group_id=14735&atid=114735

As Sivakumar says, the reason it's failing is because pysnmp is looking for MIBs with a .pyc or .pyw extension. pysnmp gets these extensions from imp.get_suffixes(). Based on the way pysnmp deals with the extensions returned from this function, the .pyw entry will overwrite the .py entry. The fix I proposed will simply ignore the .pyw extension.

If you install the library from the .egg it should work fine because the .egg includes compiled (pyc) MIBs.

孤独患者 2024-09-27 00:06:35

您无法加载 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() 获得的路径中

You are not able to load the MIB file.

Can you check :

>>> print builder.MibBuilder().getMibPath()

Usually this should be ok as the mib instances should be in

pysnmp/smi/mibs/instances

Code where error is raised in 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]")
            )

Usually this should get solved by calling setMibPath on the mibBuilder instance before calling loadModules.

Since the path you are getting

C:\Python27\lib\pysnmp\smi\mibs\instances, 
C:\Python27\lib\pysnmp\smi\mibs, 
C:\Python27\lib\pysnmp_mibs

Why don't you move the file to one of these directories?
The place where it is currently located

  • C:\Python27\Lib\pysnmp\smi\mibs

is not among the paths that you got via builder.MibBuilder().getMibPath()

演出会有结束 2024-09-27 00:06:34

如果缺少 mib,请确保您已使用 pip install pysnmp 首先执行了 pip install pysnmp-mibs

if a mib is missing make sure you have performed a pip install pysnmp-mibs first if you used pip install pysnmp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文