我有来自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]'末尾的数字随着每次执行而改变(看起来像是时间戳或类似的东西)。我使用的是Python2.7和最新版本的pySNMP (4.2.1)。有人知道这个示例代码有什么问题吗?
发布于 2012-01-28 20:46:13
这是pysnmp 4.2.1中的一个bug,这个bug已经被修复到了最新的pysnmp候选版本中(由于某种原因,这个bug似乎更多地出现在Mac上)。
以下是当前最新rc的链接:
http://sourceforge.net/projects/pysnmp/files/pysnmp/4.2.2/pysnmp-4.2.2rc5.tar.gz/download
-ilya
https://stackoverflow.com/questions/8952686
复制相似问题