我正在尝试使用SNMP get设置一个值。我已经测试过OID可以通过MIB浏览器写入。我可以使用另一个脚本来获取值,但是使用set就没有意义了。
from pysnmp.hlapi import *
engine = SnmpEngine()
community = CommunityData('public', mpModel=1)
transport = UdpTransportTarget(('target', 161))
context = ContextData()
# Your OID goes here.
identity = ObjectIdentity('.1.3.6.1.4.1.32050')
# If this was a string value, use OctetString() instead of Integer().
new_value = Integer(1)
type = ObjectType(identity, new_value)
# Setting lookupMib=False here because this example uses a numeric OID.
g = setCmd(engine, community, transport, context, identity, type, lookupMib=False)
errorIndication, errorStatus, errorIndex, varBinds = next(g)
print(errorIndication, varBinds)我看到的错误
line 17, in <module>
errorIndication, errorStatus, errorIndex, varBinds = next(g)
pysnmp.smi.error.SmiError: ObjectIdentity object not properly initialized发布于 2021-03-27 20:07:54
在context之后,setCmd期望ObjectType类的参数(例如,两个oid +context),但这里不是这种情况。在我看来,identity在这里是多余的。
试着这样做:
g = setCmd(engine, community, transport, context, type, lookupMib=False)(顺便说一句,您应该避免调用变量type,这是一个预定义的python类。)
发布于 2021-03-28 22:16:40
在修复了前面答案中描述的问题之后,仅仅通过代码检查,它就会提示OID .1.3.6.1.4.1.32050不能是对象实例,因为它是企业分支。通过将identity设置为.1.3.6.1.2.1.1.5.0,您可以在不到一分钟的时间内证明这一点。
https://stackoverflow.com/questions/66824056
复制相似问题