python-3.x - 带有 PYSNMP 的 Python 集
问题描述
我正在尝试使用 SNMP get 设置一个值。我已经测试过 OID 可以用 MIB 浏览器写入。我可以使用另一个脚本获取值,但使用集合没有意义。
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
解决方案
在您解决了上一个答案中描述的问题后,仅通过代码检查它就会尖叫 OID .1.3.6.1.4.1.32050 一定不是对象实例,因为它是一个企业分支。您可以通过将身份设置为 .1.3.6.1.2.1.1.5.0 在不到一分钟的时间内证明这一点。
推荐阅读
- java - 更改添加到堆栈的变量值而不更改堆栈?
- python - 我不断收到 TypeError:当我尝试运行我的代码时,“str”对象不能被解释为整数
- python - 尝试使用 pip 卸载时出现“PermissionError:[Errno 13]”
- python-3.x - 将文件路径(字符串)附加到列表时添加到路径的额外反斜杠
- javascript - chartjs的y轴不显示?
- c++ - 将指针传递给模板参数时类型推导的规则是什么
- sql - 从查询的列到另一个查询的行的 SQL
- python - 通过循环遍历特定数据框列中的行来生成 QR 码
- javascript - 如何摆脱js计算器中的前导零
- php - 带有嵌套 Where 子句的 Eloquent