我有来自 pysnmp 页面的以下示例:# GET Command Generator from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, \
errorIndex, varBinds = cmdgen.CommandGenerator().getCmd(
# SNMP v1
# cmdgen.CommunityData('test-agent', 'public', 0),
# SNMP v2
cmdgen.CommunityData('test-agent', 'public'),
# SNMP v3
# cmdgen.UsmUserData('test-user', 'authkey1', 'privkey1'),
cmdgen.UdpTransportTarget(('localhost', 161)),
# Plain OID
(1,3,6,1,2,1,1,1,0),
# ((mib-name, mib-symbol), instance-id)
(('SNMPv2-MIB', 'sysDescr'), 0)
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
else:
for name, val in varBinds:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
我确保 SNMP 正在我的机器上运行。我使用以下命令在控制台中签入:
snmpget -v2c -Cf -c public localhost 1.3.6.1.2.1.1.1.0
效果很好。如果我执行上面的 python 代码,我会收到以下错误:
SmiError: MIB module "pysnmp/smi/mibs/SNMP-COMMUNITY-MIB.py" load error: MIB module "pysnmp/smi/mibs/SNMP-FRAMEWORK-MIB.py" load error: Bad OctetString initializer '[128, 0, 79, 184, 5, 192, 168, 1, 50, 371, 210, 26, 162, 157]'
最后的数字随着每次执行而变化(似乎是时间戳或类似的东西)。我正在使用 python 2.7 和最新版本的 pySNMP (4.2.1)。有谁知道这个示例代码有什么问题?