[Python] Having trouble connecting to Cisco router through SecureCRT with a python script

Discussão em 'Python' iniciado por Stack, Abril 11, 2025.

  1. Stack

    Stack Membro Participativo

    So I am trying to connect through SecureCRT to a Cisco router with the python code below. If I run the script in vscode the variable connection_string looks like this "/SSH2 /L username /PASSWORD password 192.168.202.144", so that looks just fine. But in crt I get a script error "Connection Failed" and it points to "crt.Session.ConnectInTab(connection_string)".

    Thanks in advance :)

    I am omitting the "modify" function just to scale down the post a bit.

    import os
    from dotenv import load_dotenv
    from pathlib import Path

    dotenv_path = Path(r'C:\Users\user\Desktop\PythonScripts\.env')
    load_dotenv(dotenv_path=dotenv_path)
    username = os.getenv('env_username')
    password = os.getenv('env_password')


    def main():
    # Open list with IP addresses
    with open(r"C:\Users\user\Desktop\PythonScripts\ipaddresses", "r") as f:

    for host in f:

    modified_host = modify(host)

    connection_string = f"/SSH2 /L {username} /PASSWORD {password} {modified_host}"

    print(f"Connection string: {connection_string}")

    crt.Session.ConnectInTab(connection_string)


    main()

    Continue reading...

Compartilhe esta Página