PySNMP:加载错误:错误的 OctetString 初始值设定项
我从 pysnmp 页面有以下示例: # GET 命令生成器 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)。 有谁知道这个示例代码有什么问题吗?
I have the following example from the pysnmp page:
# 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())
I made sure that SNMP is running on my machine. I checked in the console with the following command:
snmpget -v2c -Cf -c public localhost 1.3.6.1.2.1.1.1.0
Which worked fine.
If i execute the python code above I get the following error:
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]'
The numbers at the end change with each execution (seems to a timestamp or somehting like that).
I'm using python 2.7 and the most recent version of pySNMP (4.2.1).
Does anyone know what's the problem with this example code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 pysnmp 4.2.1 中的一个错误,已修复到最新的 pysnmp 候选版本中(由于某种原因,该错误似乎在 Mac 上更频繁地发生)。
这是当前最新 rc 的链接:
http://sourceforge.net/projects/pysnmp/files/pysnmp/4.2.2/pysnmp-4.2.2rc5.tar.gz/download
-ilya
That is a bug in pysnmp 4.2.1 which has been fixed to the latest pysnmp release candidates (it looks like this bug more frequently occurs on Macs for some reason).
Here's a link to currently most recent rc:
http://sourceforge.net/projects/pysnmp/files/pysnmp/4.2.2/pysnmp-4.2.2rc5.tar.gz/download
-ilya