etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
576 stars 194 forks source link

pyasn1.error.PyAsn1Error: Uninitialized ASN.1 value ("__bool__" attribute looked up) #86

Closed denisbondar closed 6 years ago

denisbondar commented 6 years ago

Hi, Sorry for the stupid question. I can not understand why I get the following error. Please help fix it. This code works everywhere (on Debian, FreeBSD, CentOS, other Ubuntu), even under Windows, but for some reason not on the production server.

Python 3.5.2, Ubuntu 16.04.3 LTS Package versions:

# pip3 freeze --local
certifi==2017.7.27.1
chardet==3.0.4
command-not-found==0.3
idna==2.6
language-selector==0.1
List==1.3.0
ply==3.10
pyasn1==0.3.7
pycryptodome==3.4.7
pycurl==7.43.0
pygobject==3.20.0
pysmi==0.1.3
pysnmp==4.3.10
python-apt==1.1.0b1
python-debian==0.1.31
python-systemd==231
requests==2.18.4
six==1.11.0
ssh-import-id==5.6
ufw==0.35
unattended-upgrades==0.1
urllib3==1.22

My code:

getCmd(snmp_engine, auth_data, transport_target, ContextData(), *var_binds,
       **dict(cbFun=snmp_response_handler, cbCtx=(transport_target)))

I got the following error.

Traceback (most recent call last):
  File "snmpworker.py", line 305, in <module>
    **dict(cbFun=snmp_response_handler, cbCtx=(transport_target)))
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 129, in getCmd
    vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun,
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds
    __varBinds.append(varBind.resolveWithMib(mibViewController))
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/rfc1902.py", line 845, in resolveWithMib
    self.__args[0].resolveWithMib(mibViewController)
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/rfc1902.py", line 421, in resolveWithMib
    self.__oid
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/view.py", line 206, in getNodeNameByOid
    nodeName, mibMod['oidToLabelIdx'], mibMod['labelToOidIdx']
  File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/view.py", line 179, in __getOidLabel
    if not nodeName:
  File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/base.py", line 249, in __bool__
    return self._value and True or False
  File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/base.py", line 164, in plug
    raise error.PyAsn1Error('Uninitialized ASN.1 value ("%s" attribute looked up)' % name)
pyasn1.error.PyAsn1Error: Uninitialized ASN.1 value ("__bool__" attribute looked up)
etingof commented 6 years ago

May be it has something to do with the var_binds you pass in... What is there?

The best way to troubleshoot this would be to enable pysnmp debugging and send it over here (make sure you do not have secrets there).

from pysnmp import debug
debug.setLogger(debug.Debug('all'))
denisbondar commented 6 years ago

Thank you so much!

I found a problem in the formation of var_binds. Some elements were is Null.