PySNMP Error: pysnmp.smi.error.SmiError

我是研究僧i 提交于 2019-12-14 03:56:51

问题


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?


回答1:


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




回答2:


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.




回答3:


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()




回答4:


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/)




回答5:


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



来源:https://stackoverflow.com/questions/3730925/pysnmp-error-pysnmp-smi-error-smierror

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!