[pysnmp-users] UnboundLocalError: local variable 'errorIndication' referenced before assignment
Brought to you by:
elie
From: Patrick O. <pa...@og...> - 2015-10-28 19:47:31
|
Hello, I ran into a problem after upgrading to pysnmp 4.3.0. Just running snmpwalk it looks like this: $ snmpwalk -v2c -c public 172.29.50.5 1.3.6.1.4.1.9.9.46.1.4.2 SNMPv2-SMI::enterprises.9.9.46.1.4.2 = No Such Object available on this agent at this OID The problem seems to be when you run a nextCmd against an object which currently doesn't exist. The code below works with pysnmp 4.2.5 from pysnmp.entity.rfc3413.oneliner import cmdgen cmdGen = cmdgen.CommandGenerator() errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( cmdgen.CommunityData('public'), cmdgen.UdpTransportTarget(('172.29.50.5', 161)), '1.3.6.1.4.1.9.9.46.1.4.2', lookupMib=False, ) if errorIndication: print(errorIndication) else: if errorStatus: print('%s at %s' % ( errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex)-1] or '?' ) ) else: for varBindTableRow in varBindTable: for name, val in varBindTableRow: print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) As the object doesn't exist on the device nothing is printed out. However running the same code with 4.3.0 gives this error: Traceback (most recent call last): File "<stdin>", line 5, in <module> File "/Users/patrick/.virtualenvs/prod/lib/python2.7/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 222, in nextCmd return errorIndication, errorStatus, errorIndex, varBindTable UnboundLocalError: local variable 'errorIndication' referenced before assignment Is this something which can be solved in an easy way? Best regards Patrick |