pysnmp icon indicating copy to clipboard operation
pysnmp copied to clipboard

pysnmp usinng with SNMP V3

Open jhonyfre opened this issue 2 years ago • 3 comments

Hello, I'm trying to user pysnmp with SNMPv3 but I always get this error:

from pysnmp.hlapi import * Traceback (most recent call last): File "C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages\pysnmp\smi\builder.py", line 18, in PY_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER ^^^^^^^^^^^^^^ AttributeError: module 'importlib' has no attribute 'util'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages\pysnmp\smi\builder.py", line 23, in raise ImportError() ImportError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages\pysnmp\hlapi_init_.py", line 9, in from pysnmp.smi.rfc1902 import * File "C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages\pysnmp\smi\rfc1902.py", line 10, in from pysnmp.smi.builder import ZipMibSource File "C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages\pysnmp\smi\builder.py", line 26, in import imp ModuleNotFoundError: No module named 'imp'

I updated python and now I'm using Python 3.12.0 and this version of pysnmp Name: pysnmp Version: 4.4.12 Summary: SNMP library for Python Home-page: https://github.com/etingof/pysnmp Author: Ilya Etingof Author-email: [email protected] License: BSD Location: C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages Requires: pyasn1, pycryptodomex, pysmi Required-by: pysnmp-mibs

jhonyfre avatar Nov 01 '23 15:11 jhonyfre

You might read #429 and https://github.com/lextudio/pysnmp/issues/10

lextm avatar Nov 01 '23 17:11 lextm

I solve them by changing the site-packages\pysnmp\smi\builder.py


try:
    import importlib
    import importlib.util
    import importlib.machinery

    try:
        PY_MAGIC_NUMBER = importlib.util.MAGIC_NUMBER
        SOURCE_SUFFIXES = importlib.machinery.SOURCE_SUFFIXES
        BYTECODE_SUFFIXES = importlib.machinery.BYTECODE_SUFFIXES

    except Exception:
        raise ImportError()

except ImportError:
    import imp

jovileung avatar Mar 27 '24 02:03 jovileung

As far as we know 4.4.12 has many known issues with Python 3.10+, so you will have to patch it in more places if that's your choice.

We announced our plan to take over the ecosystem in #429, and you can see projects like OpenStack and Home Assistant have already switched to our fork.

lextm avatar Mar 27 '24 05:03 lextm