etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
576 stars 196 forks source link

pysnmp.smi.error.SmiError: ObjectType object not fully initialized #378

Open Ardeshirr opened 4 years ago

Ardeshirr commented 4 years ago

I run the following code to set an OID in Pysnmp and get the following error. I would appreciate if any one help me on this!

def construct_value_pairs(list_of_pairs): pairs = [] for key, value in list_of_pairs.items(): pairs.append(hlapi.ObjectType(hlapi.ObjectIdentity(key), value)) return pairs , print(pairs)

def set(target, value_pairs, CommunityData= hlapi.CommunityData('public',mpModel=0), port=1883, engine=hlapi.SnmpEngine(), context=hlapi.ContextData()): handler = hlapi.setCmd( engine, CommunityData, hlapi.UdpTransportTarget((target, port)), context, *construct_value_pairs(value_pairs) ) return fetch(handler, 1)[0]

def cast(value): try: return int(value) except (ValueError, TypeError): try: return float(value) except (ValueError, TypeError): try: return str(value) except (ValueError, TypeError): pass return value

def fetch(handler, count): result = [] for i in range(count): try: error_indication, error_status, error_index, var_binds = next(handler) if not error_indication and not error_status: items = {} for var_bind in var_binds: items[str(var_bind[0])] = cast(var_bind[1]) result.append(items) else: raise RuntimeError('Got SNMP error: {0}'.format(error_indication)) except StopIteration: break return result

def runset(TCIPAddress): threading.Timer(1,runget,[TCIPAddress]).start() set(TCIPAddress, {"1.3.6.1.4.1.1206.4.2.1.1.5.1.6.1" : "8"}) if name == "main": ListTCID = [] ListTCID.append('192.168.10.108') for siginfo in ListTCID: runset(siginfo)

Ardeshirr commented 4 years ago

Traceback (most recent call last): File "C:/HILS/hilsrun1 - Ardy Test.py", line 98, in runset(siginfo) File "C:/HILS/hilsrun1 - Ardy Test.py", line 43, in runset set(TCIPAddress, {"1.3.6.1.4.1.1206.4.2.1.1.5.1.6.1" : "8"}) File "C:/HILS/hilsrun1 - Ardy Test.py", line 54, in set return fetch(handler, 1)[0] File "C:/HILS/hilsrun1 - Ardy Test.py", line 75, in fetch error_indication, error_status, error_index, var_binds = next(handler) File "C:\HILS\pysnmp\hlapi\asyncore\sync\cmdgen.py", line 217, in setCmd lookupMib=options.get('lookupMib', True))) File "C:\HILS\pysnmp\hlapi\asyncore\cmdgen.py", line 241, in setCmd contextData.contextName, vbProcessor.makeVarBinds(snmpEngine, varBinds), File "C:\HILS\pysnmp\hlapi\varbinds.py", line 34, in makeVarBinds elif isinstance(varBind[0][0], tuple): # legacy File "C:\HILS\pysnmp\smi\rfc1902.py", line 708, in getitem raise SmiError('%s object not fully initialized' % self.class.name) pysnmp.smi.error.SmiError: ObjectType object not fully initialized

lextm commented 1 year ago

You didn't provide well formatted and complete code, so I don't think anyone can give you an answer.