Search code examples
pythonpython-2.7pysnmp

NoSuchObjectError pysnmp


I am currently getting an error when I pass my pysnmp operation an oid. The error I am getting is

*************************NoSuchObjectError({'str': "Can't resolve node name ::(u'1', u'3', u'6', u'1', u'4', u'1', u'9', u'9', u'91', u'1', u'2', u'1', u'1', u'4') at "})***********

and here is my code:

def SNMPWalkChildren(ipAddress, communityString, parentOID):
result = ""
try:
    DebugCode(ipAddress + " " + communityString + " " + parentOID)
    cmdGen = cmdgen.CommandGenerator()

    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
        cmdgen.CommunityData(communityString),
        cmdgen.UdpTransportTarget((ipAddress, 161)),
        parentOID
    )

    if errorIndication:
        DebugCode(errorIndication)
    else:
        if errorStatus:
            DebugCode('%s at %s' % (
                errorStatus.prettyPrint(),
                errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
                )
            )
        else:
            for varBindTableRow in varBindTable:
                for name, val in varBindTableRow:                       
                    result += "\"" + str(name.prettyPrint()) + "\"" + ', \n'
                    DebugCode(name.prettyPrint())
    DebugCode(result[:-2])
    return result[:-2]
except Exception as e:
    DebugCode(str(e))

Solution

  • Make sure that parentOID is an (ascii or utf-8) string:

    '1.3.6.1.4.1.9.9.91.1.2.1.1.4'
    

    or a tuple of integers:

    (1, 3, 6, 1, 4, 1, 9, 9, 91, 1, 2, 1, 1, 4)
    

    but NOT unicode string (u'1.3.6.1.4.1.9.9.91.1.2.1.1.4').