py-junos-eznc
py-junos-eznc copied to clipboard
serial port gets locked if wrong password is used initailly
When I enter a wrong password then again create a device and connect, I get an error saying serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5).
Step to replicate the issue.
#!/usr/bin/python3
from jnpr.junos import Device
from jnpr.junos.utils.config import Config
def connect_device(password,i=0):
try:
with Device(
user="root",
port="COM3",
mode="serial",
passwd=password,
gather_facts=False,
conn_open_timeout=1.5,
) as dev:
cu = Config(dev)
except Exception as err:
print(f"failed with: {err}")
finally:
print(i)
i += 1
i= 0
password_list = ["wrong password", "right password"]
while(i<2):
password = password_list[i]
connect_device(password,i)
i+=1
Traceback:
Exception occurred: login:ConnectAuthError(host: None, msg: Bad username/password)
failed with: ConnectAuthError(host: None, msg: Bad username/password)
0
ERROR: login:open_failed:None
Complete traceback message: Traceback (most recent call last):
File "C:\Users\*\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\transport\tty_serial.py", line 44, in _tty_open
self._ser.open()
File "C:\Users\*\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\*\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\console.py", line 207, in open
self._tty_login()
File "C:\Users\*\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\console.py", line 316, in _tty_login self._tty.login()
File "C:\Users\*\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\transport\tty.py", line 115, in login
self._tty_open()
File "C:\Users\*AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\jnpr\junos\transport\tty_serial.py", line 46, in _tty_open
raise RuntimeError("open_failed:{}".format(err.strerror))
RuntimeError: open_failed:None
failed with: open_failed:None
1