Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serial port gets locked if wrong password is used initailly #1243

Open
Aaron-MJohn opened this issue Apr 11, 2023 · 0 comments
Open

serial port gets locked if wrong password is used initailly #1243

Aaron-MJohn opened this issue Apr 11, 2023 · 0 comments

Comments

@Aaron-MJohn
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants