PySNMP Error: pysnmp.smi.error.SmiError

10,646

Solution 1

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

Solution 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.

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

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

Share:
10,646
Lulu
Author by

Lulu

Updated on June 14, 2022

Comments

  • Lulu
    Lulu about 2 years

    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?

    • pyfunc
      pyfunc over 13 years
      @AaronMcSmooth : The solution has been provided here so I guess we can mark the other question as duplicate as the other one is more recent.
    • aaronasterling
      aaronasterling over 13 years
      @pyfunc. Already done, I hadn't noticed the other one was more recent. I can't undo my vote but I did vote to close that one as well. If anyone wants to vote on it, it's at:stackoverflow.com/questions/3732439/…
  • Lulu
    Lulu over 13 years
    C:\Python27\lib\pysnmp\smi\mibs\instances, C:\Python27\lib\pysnmp\smi\mibs, C:\Python27\lib\pysnmp_mibs
  • Lulu
    Lulu over 13 years
    why is it looking for "SNMPv2-MIB.py[co]" instead of SNMPv2-MIB.py?
  • William John Holden
    William John Holden over 5 years
    Six years later you would think this would be mentioned at snmplabs.com/pysnmp/index.html, but it isn't.
  • Riccardo Manfrin
    Riccardo Manfrin over 4 years
    This solved for me.. I was stripping the pyc's around to squeeze on size, but pysnmp didn't like it so restoring it with a simple python -m compileall ./ diddathing.