pysnmp.smi.error.MibNotFoundError: No module __SNMP-FRAMEWORK-MIB loaded at <pysnmp.smi.builder.MibBuilder object at 0x0418A110>

泪湿孤枕 提交于 2019-12-13 03:19:09

问题


I'm just starting out in Python so please bear with me. I've been trying to find a solution to this error for the last 3 days in google, Stack Overflow, Github, python.org and also snmplabs.com. I have progressed from other errors (thanks in part to the above websites) but this one has me stumped and I cannot seem to resolve it.

I'm running the following versions of stuff: Windows 10 Enterprise 64-bit python 3.6, pysnmp 4.4.4, pyasn1 0.2.3 and I am using paramiko for ssh and tkinter as a GUI My project is composed using Visual Studio Code v1.20.1

Basically I have made a python app that logs into a cisco switch and adds a vlan to a trunk, replaces it with another vlan, or removes both vlans

Each time one of these vlan changes is made the script sends an snmp trap to an NMS saying what was just done. The trap is just an OID as follows:

def sendTrap(system):
debug.setLogger(debug.Debug('msgproc'))

next(sendNotification(SnmpEngine(),
CommunityData('blahblah'),
UdpTransportTarget(('1.1.1.1', 162)),
ContextData(),
'trap',
# sequence of custom OID-value pairs
[ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'), OctetString(system))]))

Some other stuff happens as well, like the background colour when a change is made, and a timer begins which resets everything back after a predetermined amount of time.

The program works flawlessly when I run it as a python script.

However, when I use cx_freeze to create an exe file of my little app everything works EXCEPT for the snmp trap and I currently get the following traceback error:

    2018-02-17 02:17:39,956 pysnmp: running pysnmp version 4.4.4
    2018-02-17 02:17:39,957 pysnmp: debug category 'msgproc' enabled
    Exception in Tkinter callback
    Traceback (most recent call last):

      File "C:\Python\Python36-32\lib\site-packages\pysnmp\entity\engine.py", line 91, in __init__
        '__SNMP-FRAMEWORK-MIB', 'snmpEngineMaxMessageSize')
      File "C:\Python\Python36-32\lib\site-packages\pysnmp\smi\builder.py", line 409, in importSymbols
        'No module %s loaded at %s' % (modName, self)
    pysnmp.smi.error.MibNotFoundError: No module __SNMP-FRAMEWORK-MIB loaded at pysnmp.smi.builder.MibBuilder object at 0x034C9150

The module __SNMP-FRAMEWORK-MIB is located in C:\Python\Python36-32\Lib\site-packages\pysnmp\smi\mibs\instances and I have this folder included in the setup file as follows (Now THIS is where I think I have gone wrong):

    options = {
'build_exe': {
    #'packages':packages,
    'include_files':[
        os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
        os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
        'C:\\Python\\Python36-32\\Lib\\site-packages\\idna',
        'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs',
        'C:\\Python\\Python36-32\\Lib\\site-packages\\pysnmp\\smi\\mibs\\instances'
     ],
},
    }

*Please ignore the weird indents as I was trying to get the format correct for presenting it here

Apologies but, although I've done a lot of reading about this over the past few days I'm not totally clued up on things like packages, modules, options and includes so it's all a bit alien to me.

If someone can see where I'm going wrong or if I need to provide more information please let me know. Any assistance would be much appreciated. Thanks


回答1:


With some great help from snippsat at python-forum I finally got this to work. Essentially cx_freeze wouldn't play nice so we ended up using pyinstaller with a little tweak to the "spec" file (As detailed at python-forum) and everything is now working.



来源:https://stackoverflow.com/questions/48837417/pysnmp-smi-error-mibnotfounderror-no-module-snmp-framework-mib-loaded-at-pys

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