我正在尝试使用以下代码执行简单的SNMP操作。请帮我弄清楚错误。
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()))
上面的代码给出了以下错误:
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
答案 0 :(得分:0)
有可能是你的系统pyasn1 pysnmp包与版本不兼容。我建议将pyasn1和pysnmp软件包(最新的软件包)放入你的$ HOME并设置$ PYTHONPATH指向每个软件包。