ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.55k stars 1.3k forks source link

netmiko import pysnmp error #3469

Open phw50365036 opened 1 month ago

phw50365036 commented 1 month ago

Description of Issue/Question

I have netmiko4.4.0 and pysnmp6.2.4 installed, and when I run the project, I get an error: pysnmp not installed; please install it: 'pip install pysnmp' The investigation found that: The source code is like this package import: from pysnmp.entity.rfc3413.oneliner import cmdgen In pysnmp6.2.4, cmdgen has a cmdgen.py file in the path: pysnmp/entity/rfc3413 netmiko4.4.0 was released on July 9, 2024. pysnmp> 5.* versions are all released after July 17, 2024. If I use pysnmp earlier than 6.2.2, there is no problem, it appears that the pysnmp author changed the file structure in 6.2.2

Setup

Netmiko version

netmiko==4.4.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

pysnmp==6.2.4

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

File "/home/new_autonet/autonet/urls.py", line 19, in <module>
    from application.config_task_manage.views import EmailSignView
  File "/home/new_autonet/application/config_task_manage/views.py", line 17, in <module>
    from core.system_manage.system_handle import get_session_aaa_data
  File "/home/new_autonet/core/system_manage/system_handle.py", line 18, in <module>
    from utils.common.auths import NetAuths
  File "/home/new_autonet/utils/common/auths.py", line 25, in <module>
    from netmiko.snmp_autodetect import SNMPDetect
  File "/usr/local/lib/python3.9/site-packages/netmiko/snmp_autodetect.py", line 32, in <module>
    raise ImportError("pysnmp not installed; please install it: 'pip install pysnmp'")
ImportError: pysnmp not installed; please install it: 'pip install pysnmp'

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue) (Paste the code between the quotes below)

ktbyers commented 1 month ago

Okay...makes sense for 5+ years there were no updates to pysnmp and then in July 2024 they released a version 5 and a version 6.

So what is needed.

In order to use the current released version of Netmiko, a user would need to install and use the older version of pysnmp (since it looks like they made a backwords incompatible change).

Tonygratta commented 1 month ago

I am working on a fix for this issue now. However, at the moment, I am experiencing some troubling exceptions when testing on Python 3.8 and 3.9 on Windows due to an issue with Python asyncio (https://github.com/python/cpython/issues/92841). Despite the exceptions, the code is still working. I am wondering if it is really necessary to fix this issue for this specific case. There might be some "dirty" solutions like this:

import sys
if sys.version_info[0] == 3 and sys.version_info[1] <= 9 and sys.platform == 'win32':
    # patch for windows 3.8-3.9 python bug https://github.com/python/cpython/issues/92841
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Any suggestions?

phw50365036 commented 1 month ago

My project is running in linux, I think I have encountered a very similar problem with you, it seems that the task has ended, but the asynico of asynchronous management mistakenly thinks that the task has not ended, unfortunately: I didn't know much about python's asyncism, so I asked GPT, and it suggested writing programs to cancel tasks, so I was wondering if it was possible to give tasks a name when adding tasks, and use code to cancel the corresponding tasks when a certain task already has a return value. I don't know if it's feasible, but I hope it can give you some inspiration.

ktbyers commented 1 month ago

@Tonygratta Yeah, I wouldn't think fixing that is necessary from Netmiko's perspective.

Bierchermuesli commented 2 weeks ago

I guess the pysnmp error should be fixed with https://github.com/ktbyers/netmiko/pull/3473. In the meantime pysnmp >7.x was released.

Ilya, the original pysnmp author, sadly passed away. This might be the reason for the long (now short) release cycle. new pip releases are published from lextudio fork.