etingof / pysnmp

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

pysnmp usinng with SNMP V3 #451

Open jhonyfre opened 8 months ago

jhonyfre commented 8 months ago

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: etingof@gmail.com License: BSD Location: C:\Users\ramirezjh\AppData\Local\Programs\Python\Python312\Lib\site-packages Requires: pyasn1, pycryptodomex, pysmi Required-by: pysnmp-mibs

lextm commented 8 months ago

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

jovileung commented 3 months ago

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
lextm commented 3 months ago

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.