etingof / pysnmp

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

AttributeError: 'module' object has no attribute 'noValue' #224

Closed ecrsecurity closed 5 years ago

ecrsecurity commented 5 years ago

Any python library I attempt to use which imports pysnmp gives the same error.

, line 1, in <module>
    from pysnmp.hlapi import *
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/hlapi/__init__.py", line 7, in <module>
    from pysnmp.proto.rfc1902 import *
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc1902.py", line 9, in <module>
    from pysnmp.proto import rfc1155, error
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc1155.py", line 50, in <module>
    class NetworkAddress(univ.Choice):
  File "/usr/local/lib/python2.7/dist-packages/pysnmp/proto/rfc1155.py", line 55, in NetworkAddress
    def clone(self, value=univ.noValue, **kwargs):
AttributeError: 'module' object has no attribute 'noValue'

Yes, I have read https://github.com/etingof/pysnmp/issues/69 and several other similar bug reports in projects which use pysnmp all of which point to updating pyasn1. However I have already updated pyasn1, and the solution of removing the OS packaged version is not an option for me because I have other packages which require python-asn1 as a dependency.

pip search pysnmp
pysnmp-mib (0.1.0a)   - A collection of pre-compiled PySNMP MIBs
pysnmp-mibs (0.1.6)   - A collection of IETF & IANA MIBs pre-compiled for PySNMP
pysnmp (4.4.6)        - SNMP library for Python
  INSTALLED: 4.4.6 (latest)
pysnmp-apps (0.5.3)   - SNMP command-line tools
pysnmp-se (3.5.2)     - Python SNMP Toolkit (Speed Enhanced)
snmpy (1.0.0)         - Simple pysnmp wrapper.
nelsnmp (0.2.8)       - A wrapper module for pysnmp
pysnmpcrypto (0.0.3)  - Strong cryptography support for PySNMP (SNMP library for Python)

pip search pyasn1
pyasn1 (0.4.4)          - ASN.1 types and codecs
  INSTALLED: 0.4.4 (latest)
pyasn1-modules (0.2.2)  - A collection of ASN.1-based protocols modules.
  INSTALLED: 0.2.2 (latest)
rfc3161 (1.0.7)         - Python implementation of the RFC3161 specification, using pyasn1
rfc3161ng (2.1.1)       - Python implementation of the RFC3161 specification, using pyasn1

I have some packages installed by my package manager also on Kali (Debian) Linux

dpkg-query -W | grep pysnmp

python3-pysnmp4 4.4.6+repack1-1
python-pysnmp4  4.4.6+repack1-1
python-pysnmp4-apps 0.3.2-1
python-pysnmp4-mibs 0.1.3-1
python3-pysnmp4 4.4.6+repack1-1

dpkg-query -W | grep pyasn1

python3-asn1crypto  0.24.0-1
python3-pyasn1  0.4.2-3
python-asn1crypto   0.24.0-1
python-pyasn1   0.4.2-3
python-pyasn1-modules   0.2.1-0.2

Other sources on the web claim that this problem is caused by pyasn1 version < 0.2.3 but even the OS package is newer than that. Is this an error from out of date pyasn1? If so, what is the minimum required version?

etingof commented 5 years ago

This is suspicious. Is is possible that you have some other pyasn1 version installed which is not visible to pip and dpkg?

One way to track that down would be to run a simple script (which fails) giving -v option to your Python interpreter along the way (to see which modules it actually imports).

python -v your-failing-script.py 2>&1 | grep pyasn1
ecrsecurity commented 5 years ago

Good call. I found an old pyasn1 .0.1.9 in my dist-packages directory, wiped it, and problem solved. Thanks!

This is suspicious. Is is possible that you have some other pyasn1 version installed which is not visible to pip and dpkg?

One way to track that down would be to run a simple script that fails that way giving -v option to your Python interpreter (to see which modules it actually imports).

python -v your-failing-script.py 2>&1 | grep pyasn1
etingof commented 5 years ago

Awesome!