Anuradha Nair
Anuradha Nair

Reputation: 81

No SNMP response received before timeout

I am a biginer for Pysnmp . I just installed it and started study. When i work with example for Synchronous Command Generator i am getting an error that "No SNMP response received before timeout".Any one please help!! My code is

from pysnmp.entity.rfc3413.oneliner import cmdgen

cmdGen = cmdgen.CommandGenerator()

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
    cmdgen.CommunityData('public'),
    cmdgen.UdpTransportTarget(('localhost', 161)),
    '1.3.6.1.2.1.1.1.0',
    '1.3.6.1.2.1.1.6.0'
)

# Check for errors and print out results
if errorIndication:
    print(errorIndication)
else:
    if errorStatus:
        print('%s at %s' % (
            errorStatus.prettyPrint(),
            errorIndex and varBinds[int(errorIndex)-1] or '?'
            )
        )
    else:
        for name, val in varBinds:
            print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))

Upvotes: 1

Views: 9794

Answers (3)

eya-cfu
eya-cfu

Reputation: 11

OP didn't specify OS so if you're testing on Windows this may help:

  • Make sure you have the SNMP service installed (see here)
  • Go to services.msc and add your "localhost" under hosts and community "public" SNMP service

Upvotes: 1

Tints
Tints

Reputation: 21

There is nothing wrong with your code but could be two possible reasons why you are getting that response.

  1. your 'localhost' has no snmp configured in it. Try connecting to a device ip that has snmp configured.

  2. your communityData string is not 'public' on the device(localhost).

Check these two things and lets see how it goes. if you do not have a device to work on then trying out GNS3 would be the best option.

Upvotes: 1

Anuradha Nair
Anuradha Nair

Reputation: 81

Corrected the issue by installing SNMP (on Linux OS) and changing its configuration file.

  1. apt-get update && apt-get install snmpd
  2. Add "udp:161 udp6:161" in /var/lib/snmp/snmpd.conf

Upvotes: 1

Related Questions