我从以下位置下载示例:
http://xxxx.com/pysnmp/examples/v3arch/twisted/agent/cmdrsp/agent-side-mib-implementations.html
并尝试运行:
snmpwalk -v2c -c 公共 127.0.0.1 .1.3.6
获取:
Unhandled Error
Traceback (most recent call last):
File "implementing-scalar-mib-objects1.py", line 81, in <module>
reactor.run()
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1261, in run
self.mainLoop()
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1270, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 896, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/usr/lib/python2.7/dist-packages/pysnmp/carrier/base.py", line 70, in _cbFun
self, transportDomain, transportAddress, incomingMessage
File "/usr/lib/python2.7/dist-packages/pysnmp/entity/engine.py", line 152, in __receiveMessageCbFun
self, transportDomain, transportAddress, wholeMsg
File "/usr/lib/python2.7/dist-packages/pysnmp/proto/rfc3412.py", line 433, in receiveMessage
PDU, maxSizeResponseScopedPDU, stateReference)
File "/usr/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/cmdrsp.py", line 150, in processPdu
self.handleMgmtOperation(snmpEngine, stateReference, contextName, PDU)
File "/usr/lib/python2.7/dist-packages/pysnmp/entity/rfc3413/cmdrsp.py", line 293, in handleMgmtOperation
rspVarBinds = mgmtFun(*varBinds, **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 261, in readNextVars
return self.flipFlopFsm(self.fsmReadNextVar, *varBinds, **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/instrum.py", line 227, in flipFlopFsm
rval = mgmtFun((tuple(name), val), **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 527, in readGetNext
return node.readGetNext((nextName, val), **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 660, in readGetNext
return MibTree.readGetNext(self, varBind, **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 527, in readGetNext
return node.readGetNext((nextName, val), **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 780, in readGetNext
return self.readGet(varBind, **context)
File "/usr/lib/python2.7/dist-packages/pysnmp/smi/mibs/SNMPv2-SMI.py", line 761, in readGet
return self.name, self.getValue(name, **context)
exceptions.TypeError: getValue() got an unexpected keyword argument 'cbCtx'
在 v1 中我得到空答案:
$ snmpwalk -v 1 -c public 127.0.0.1 1.3.6
End of MIB
Debian 测试中的 python3-pysnmp4 4.4.6-1。
当您引用 python3-pysnmp-4.4.6 时,您的回溯来自 Python 2.7。请确保您使用的 pysnmp 版本与示例兼容。
顺便说一句,您正在运行的示例脚本将不会响应 SNMP v1 查询,除非您添加:
config.addVacmUser(snmpEngine, 1, 'my-area', 'noAuthNoPriv', (1, 3, 6, 5))
呼叫它。