I have the following code
def SetSnmpOid(oid, snmpDataType, value):
try:
global SNMP_COMMUNITY
global SNMP_HOST
global SNMP_PORT
cmdGen = cmdgen.CommandGenerator()
# Send to first Telnet IP address, different port for SNMP
dataType = "rfc1902." + snmpDataType
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
cmdgen.CommunityData(SNMP_COMMUNITY, mpModel=0),
cmdgen.UdpTransportTarget((SNMP_HOST, SNMP_PORT)),
(oid + "." + str(0), dataType(value)))
which, when run, generates this error
File "H:/code/test_script.txt.py", line 105, in SetSnmpOid
(oid + "." + str(0), dataType(value)))
TypeError: 'str' object is not callable
and I'm certain that the error refers to dataType
(which evaluates to rfc1902.integer
, which is correct). The problem seems to be using it as a function call dataType(value)
as part of a tuple.
If anyone is interested, I am trying to emulate the code found here.