{"id":7330,"library":"junos-eznc","title":"Junos EZNC (py-junos-eznc)","description":"Junos EZNC is a Python library for automating Juniper Junos devices, simplifying network management tasks for non-programmers. It provides a high-level API to connect to devices, retrieve facts, execute commands, and manage configurations using NETCONF. The current version is 2.7.6, with releases occurring periodically to add features, fix bugs, and ensure compatibility with newer Python versions and underlying dependencies.","status":"active","version":"2.7.6","language":"en","source_language":"en","source_url":"https://github.com/Juniper/py-junos-eznc","tags":["network automation","juniper","junos","netconf","ssh","network management"],"install":[{"cmd":"pip install junos-eznc","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for NETCONF communication with Junos devices.","package":"ncclient","optional":false},{"reason":"Provides an SSH client with specific Juniper-related ciphers and enhancements.","package":"juniper-paramiko","optional":false}],"imports":[{"note":"The main Device object is located within the `jnpr.junos` namespace, not the top-level package.","wrong":"import junos_eznc","symbol":"Device","correct":"from jnpr.junos import Device"},{"note":"Common exception for connection failures.","symbol":"ConnectError","correct":"from jnpr.junos.exception import ConnectError"}],"quickstart":{"code":"import os\nfrom jnpr.junos import Device\nfrom jnpr.junos.exception import ConnectError\n\nhost = os.environ.get('JUNOS_HOST', 'your_junos_device_ip')\nuser = os.environ.get('JUNOS_USER', 'your_username')\npassword = os.environ.get('JUNOS_PASSWORD', 'your_password')\n\ndev = None\ntry:\n    # hostkey_verify=False for labs/quick starts, use True in production\n    dev = Device(host=host, user=user, password=password, port=22, hostkey_verify=False)\n    dev.open()\n    print(f\"Connected to device: {dev.hostname}\")\n    print(f\"Device facts: {dev.facts['hostname']}, {dev.facts['version']}\")\n    # Example: Execute a command\n    # rpc_resp = dev.rpc.get_system_uptime_information()\n    # print(rpc_resp.find('.//up-time').text)\n\nexcept ConnectError as err:\n    print(f\"Connection error: {err}\")\nexcept Exception as err:\n    print(f\"An error occurred: {err}\")\nfinally:\n    if dev and dev.connected:\n        dev.close()\n        print(\"Disconnected from device.\")","lang":"python","description":"This quickstart demonstrates how to establish a connection to a Junos device, retrieve basic facts, and properly close the connection. It uses environment variables for credentials, making it safer for sharing. For production environments, `hostkey_verify` should be set to `True` for secure SSH connections."},"warnings":[{"fix":"Review release notes for 2.6.8 and update your code to use the new field names (e.g., `vlan-name` instead of `name` for VlanTable, `client-name` for BfdSessionTable).","message":"Field names within some tables (e.g., `VlanTable`, `BfdSessionTable`) were changed in version 2.6.8. Existing scripts relying on old field names will break.","severity":"breaking","affected_versions":">=2.6.8"},{"fix":"Always use a `try...finally` block to ensure `dev.close()` is called, even if errors occur during the connection lifetime. Alternatively, consider using `with Device(...) as dev:` for automatic resource management if your PyEZ version supports it (check documentation).","message":"PyEZ connections must be explicitly opened (`dev.open()`) and closed (`dev.close()`) to release resources. Forgetting to close can lead to lingering sessions or resource exhaustion on the device/client.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure you are using `junos-eznc` version 2.7.6 or newer for official Python 3.12+ compatibility. Always check `requires_python` in `pyproject.toml` or PyPI.","message":"Older versions of `junos-eznc` (prior to 2.7.6) may not fully support Python 3.12+ due to underlying dependency changes or internal updates.","severity":"gotcha","affected_versions":"<2.7.6"},{"fix":"Upgrade to `junos-eznc` 2.6.7 or later to gain explicit control over `look_for_keys` parameter, allowing `True`/`False` to enable/disable SSH agent lookup.","message":"The `look_for_keys` parameter for SSH authentication was introduced to control SSH agent usage. Older versions might not have this explicit control, defaulting to agent usage.","severity":"deprecated","affected_versions":"<2.6.7"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `junos-eznc` is installed via `pip install junos-eznc` in your active virtual environment. Verify the import statement: `from jnpr.junos import Device`.","cause":"The Python environment does not have `junos-eznc` installed, or it's installed in a different environment, or the import path is incorrect.","error":"ImportError: cannot import name 'Device' from 'jnpr.junos'"},{"fix":"Double-check credentials (username/password, SSH key path). Ensure the user is configured for NETCONF access on the Junos device. Verify network connectivity to the device's SSH port (22).","cause":"Incorrect username or password, or SSH key authentication failed. This can also occur if the user lacks necessary permissions on the Junos device.","error":"jnpr.junos.exception.ConnectError: Cannot connect to device: ('paramiko.ssh_exception.AuthenticationException', 'Authentication failed.')"},{"fix":"Examine the full RPC error message for details. This often includes `error-message` and `error-path`. Consult Junos documentation for the correct syntax of the command or configuration being applied.","cause":"A NETCONF RPC call failed on the Junos device. This usually indicates a syntax error in the command sent, invalid configuration, or an operational issue on the device itself.","error":"ncclient.operations.rpc.RPCError: <rpc-error>"},{"fix":"Call `dev.open()` before attempting to access `dev.facts` or other device attributes. Ensure connection success by handling `ConnectError`.","cause":"The `facts` attribute (or other operational attributes) is only available after a successful connection has been established using `dev.open()`.","error":"AttributeError: 'Device' object has no attribute 'facts'"}]}