pythonsnmppysnmp

pysnmp: printer Canon returns error "No SNMP response received before timeout" (Xerox and HP are ok)


Trying to travel true snmp with pysnmp. If my host is a Xerox or HP printer, my code is working, and I can access a value of oid in a variable varBinds[0][1]:

from pysnmp.entity.rfc3413.oneliner import cmdgen # snmp requests

cmdGen = cmdgen.CommandGenerator()
modeliod = ".1.3.6.1.2.1.25.3.2.1.3.1"
hostname = "192.168.1.100"

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
    cmdgen.CommunityData('public'),
    cmdgen.UdpTransportTarget((hostname, 161)),
    modeliod
    )

But when I'm trying to access OID value of Canon printer, than errorIndication = No SNMP response received before timeout. In the other hand, when I'm using snmpwalk with Canon's IP and the same iod, than I can receive a value.

My platform is Windows 10 x64.

How to fix problem "No SNMP response received before timeout"?

Update1

Debigging lines:

from pysnmp import debug
debug.setLogger(debug.Debug('io', 'msgproc', 'secmod'))

Debugging output is huge, so I pasted it here: https://pastebin.com/Lpyqm9NK

Update2

It's seem to be a problem in a version of SNMP get request: when I'm changing version in a snmpwalk request to 2c I'm receiving the same error: %Failed to get value of SNMP variable. Timeout.

So, the second questinon is

How to change version of snmp in my code?


Solution

  • Here is a workarround, according to documentation:

    from pysnmp.hlapi import *
    errorIndication, errorStatus, errorIndex, varBinds = next(
        getCmd(SnmpEngine(),
               CommunityData('public', mpModel=0),
               UdpTransportTarget((hostname, 161)),
               ContextData(),
               ObjectType(ObjectIdentity(modeliod))) )