pythonnetwork-programmingpysnmp

pysnmp send request sample code not working


I am new to network programming specifically to snmp. I just want to send a simple snmp request localy and see what it gives out. so far the documentation does not really say much about the send method. This what I followed as example and this. I first used them as there are but later customized them like for instance below:

from pysnmp.hlapi import *
g = getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnectionState',
                         'ipv4', '127.0.0.1', 41511,
                         'ipv4', '127.0.0.1', 993)
)
)
g.send([ObjectType(ObjectIdentity('IF-MIB', 'ifInOctets'))])

However I am getting this error:

TypeError: can't send non-None value to a just-started generator


Solution

  • What you are trying to do is to send a value to Python generator rather than to your peer SNMP agent. Just use next() instead (or put that generator it into a loop) so it will push SNMP packet out to the network on the first iteration. Here is the example.