I am trying to use the below code to perform simple SNMP operation. Please help me figure out the error.
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0),
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
elif errorStatus:
print(errorStatus)
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
The above code gives the following error:
Traceback (most recent call last):
File "tut.py", line 1, in <module>
from pysnmp.entity.rfc3413.oneliner import cmdgen
File "/usr/lib/python2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 1, in <module>
from pysnmp.entity import engine, config
File "/usr/lib/python2.6/site-packages/pysnmp/entity/engine.py", line 2, in <module>
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
File "/usr/lib/python2.6/site-packages/pysnmp/proto/rfc3412.py", line 3, in <module>
from pyasn1.compat.octets import null
ImportError: No module named compat.octets