Menu

#56 Unable to load Python source MIBs

closed-accepted
None
5
2011-03-10
2011-03-09
No

Environment: Python 2.6, Windows 7

I tried running the simple SNMP GET example in the documentation and it failed:
>>> from pysnmp.entity.rfc3413.oneliner import cmdgen
>>> errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
... cmdgen.CommunityData('my-agent', 'public', 0),
... cmdgen.UdpTransportTarget(('localhost', 161)),
... (1,3,6,1,2,1,1,1,0)
... )

The error was this:
pysnmp.smi.error.SmiError: MIB file "SNMPv2-MIB.py[co]" not found in search path

The reason it fails is because:
The __AbstractMibSource class' __init__ method in builder.py uses imp.get_suffixes() to build a list of valid Python/MIB files it can use. On my system, that function returns this: [('.pyd', 'rb', 3), ('.py', 'U', 1), ('.pyw', 'U', 1), ('.pyc', 'rb', 2)]

These values are then added to the self.__sfx dictionary, where the key value is based on the type returned from get_suffixes(). In my environment, the .pyw (type 1) replaces the .py (type 1) suffix. (Obviously, this is not intended.)

Subsequently, when MibBuilder.loadModules() is called, I get the error noted above because it is looking for a file called SNMPv2-MIB.pyw (note the w).

The attached patch will simply ignore any .pyw suffix returned from imp.get_suffixes(). There are other ways to fix this but, seeing that I can't think of any reason why a MIB would be contained in a .pyw file, this seems to be the most straight forward fix.

Discussion

  • Joshua Gallagher

    Patch to builder.py that fixes the problem.

     
  • Ilya Etingof

    Ilya Etingof - 2011-03-10
    • assigned_to: nobody --> elie
    • status: open --> open-accepted
     
  • Ilya Etingof

    Ilya Etingof - 2011-03-10
     
  • Ilya Etingof

    Ilya Etingof - 2011-03-10

    A patch against current CVS code is attached to this bug report.

     
  • Ilya Etingof

    Ilya Etingof - 2011-03-10
    • status: open-accepted --> closed-accepted
     

Log in to post a comment.