When using easysnmp
the read device, sometimes garbled characters appear in data parsing. For example, if you want to obtain VRID
the number of the device, you will encounter the following garbled characters:
# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
from easysnmp import snmp_walk
def get_vrid():
vrid_data = snmp_walk(
oids='1.3.6.1.2.1.68.1.3.1.2',
hostname='you ip address',
community='you device community',
version=2
)
for vrid in vrid_data:
print(f'vrid: {vrid} \t value:{vrid.value}')
The solution is also very simple, just snmp
add use_sprint_value=True
the parameter when setting .
# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
from easysnmp import snmp_walk
def get_vrid():
vrid_data = snmp_walk(
oids='1.3.6.1.2.1.68.1.3.1.2',
hostname='you ip address',
community='you device community',
version=2,
use_sprint_value=True # 设置 use_sprint_value 为 True
)
for vrid in vrid_data:
print(f'vrid: {vrid} \t value:{vrid.value}')
However, it should be noted that if use_sprint_value
is set to True
, snmp
some data types may be returned in a non-standard format, and the data may not be sprint_value
formatted by the function library get
and getnext
the return value of the method.