Search code examples
pythonpysnmp

msession not defined


I am trying to run this PySNMP example program

I am on Mac OS X, and I installed pysnmp by -

$ sudo /usr/local/bin/pip install pysnmp

Now when I run the program I get -

Traceback (most recent call last):
  File "pysnmptest.py", line 2, in <module>
    from pysnmp import msession
ImportError: cannot import name msession

UPDATE:

seems like pysnmp 4.x doesn't have msession, so I tried its new sample

and now I get -

Traceback (most recent call last):
  File "pysnmptest.py", line 2, in <module>
    from pysnmp.entity.rfc3413.oneliner import cmdgen
  File "/Library/Python/2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 2, in <module>
    from pysnmp.entity import engine, config
  File "/Library/Python/2.6/site-packages/pysnmp/entity/engine.py", line 2, in <module>
    from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
  File "/Library/Python/2.6/site-packages/pysnmp/proto/rfc3412.py", line 3, in <module>
    from pysnmp.smi import builder, instrum
  File "/Library/Python/2.6/site-packages/pysnmp/smi/builder.py", line 4, in <module>
    from pysnmp.smi import error
  File "/Library/Python/2.6/site-packages/pysnmp/smi/error.py", line 1, in <module>
    from pyasn1.error import PyAsn1Error
ImportError: No module named pyasn1.error

The webpage also says they have dependencies on third-party libraries -

Latest PySNMP releases (4.x and later) depend on the following:

ASN.1 library for Python used for handling ASN.1 objects Python
Cryptography Toolkit used for SNMP message authentication and encryption

How do I install them? and would it better to install from the tarball from webpage directly?


Solution

  • which version of pysmnp did you install? The example you're trying to run seems to be suited for the 1.x version of pysnmp.

    Here I've found examples for the newest 4.x version. Note they don't use msession so I guess it was removed.


    EDIT: Looks like now you have to install pyasn1 from here... I don't use OSX so I don't know what's the better method for installing software on it. On ubuntu I just did apt-get install python-pysnmp and the whole thing was installed.