timeoutsnmppysnmp

PySNMP No Response Received Before Timeout--Even with Documentation Examples


I have installed PySNMP (version 4.4.6) and am attempting to call the following function (part of a larger class):

def walk(self):
    #Walks OID to scavenge for information.
    oids={}
    for (errorIndication,
         errorStatus,
         errorIndex,
         varBinds) in nextCmd(SnmpEngine(),
                              CommunityData(self.cs),
                              UdpTransportTarget((self.device.split(".")[0], 161), timeout=60, retries=0),
                              ContextData(),
                              ObjectType(ObjectIdentity("1.3.6.1.4.1.14179.1.2.5.5"))):
        print((errorIndication,
         errorStatus,
         errorIndex,
         varBinds))

and repeatedly receive the following output:

(RequestTimedOut('No SNMP response received before timeout',),

I have triple-checked to make sure that my community string, SNMP version, device name, port, and OID are correct. I have altered the Transport timeout variable 60 seconds with no luck. My first thought was that it might be a firewall issue, but then I tried to run the simple example included in the documentation:

from pysnmp.hlapi import *

g = getCmd(SnmpEngine(),
       CommunityData('public'),
       UdpTransportTarget(('demo.pysnmp.com', 161)),
       ContextData(),
       ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))

print(next(g))

And receive the exact same output. Does anyone know what might be causing this? Unfortunately I'm on a server with few admin rights, so I can't go digging through module files changing anything. Thanks in advance for the help!


Solution

  • Your code looks good. For as long as you get the right hostname/IP out of self.device.split(".")[0].

    May be you are not getting response from your SNMP agent for one reason or the other. I'd try public SNMP agent:

    $ snmpwalk -v2c -c public demo.pysnmp.com 1.3.6
    SNMPv2-MIB::sysDescr.0 = STRING: xxxxx
    ...
    

    To make sure you do not have connectivity/firewall problems. Consider trying snmpwalk against your local SNMP agent as well. If you can't have Net-SNMP installed, consider trying snmpclitools for conducting this experiment.