Viktor Ilienko
Viktor Ilienko

Reputation: 895

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?

Upvotes: 1

Views: 2267

Answers (2)

Viktor Ilienko
Viktor Ilienko

Reputation: 895

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))) )

Upvotes: 1

Ilya Etingof
Ilya Etingof

Reputation: 5555

Make sure that you:

  • Use correct IP, SNMP community name and SNMP version (1 vs 2c) for your Canon printer
  • Your Canon printer serves the OID you are trying to GET (1.3.6.1.2.1.25.3.2.1.3.1)
  • You do not have some sort of host-based firewall which blocks traffic from your script specifically %-)

If everything seems OK, try to enable pysnmp debugging to see what goes out, what comes in (if it does) and from which IP address your Canon printer is responding. If it is responding from the IP which is different from the one you query, pysnmp will drop such response.

To enable pysnmp debugging, add this snippet at the beginning of your script:

from pysnmp import debug

debug.setLogger(debug.Debug('io', 'msgproc', 'secmod'))

UPDATE:

By default, SNMPv2c is used. To change SNMP version for v1 set mpModel to zero:

...
CommunityData('public', mpModel=0),
...

Upvotes: 0

Related Questions