Courseiva
mediumMultiple Choice

350-401 Practice Question: Writes a Python script using Paramiko to execute…

A network engineer writes a Python script using Paramiko to execute a command on a Cisco IOS device:

```python

import paramiko

ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='cisco123') stdin, stdout, stderr = ssh.exec_command('show version') output = stdout.read().decode()

print(output)

ssh.close() ```

What is a potential issue with this approach?

⚠ Common exam trap

Candidates often assume SSH automation works identically across all devices, but Cisco IOS requires an interactive shell session rather than the single-command exec channel that Paramiko's `exec_command()` uses.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

The script will fail because Cisco IOS does not support SSH command execution; it requires an interactive shell session.

Cisco IOS devices typically require an interactive shell session for command execution over SSH. The Paramiko `exec_command()` method sends a single command and expects a response, but IOS does not natively support this non-interactive mode; it expects a VTY interactive session. As a result, the script may hang, return no output, or fail to execute the command properly.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    The script will work fine because exec_command() sends the command over SSH.

    Why it's wrong here

    exec_command() requests an SSH exec channel, which sends a command string to the remote SSH server, but Cisco IOS does not implement that channel type. The IOS SSH server only provides an interactive shell session, so the command is not interpreted as CLI input. Instead, one must use invoke_shell() to establish a PTY and then send commands followed by newlines.

  • ✗

    The script will fail because the username and password are passed as plaintext; Paramiko requires key-based authentication.

    Why it's wrong here

    Paramiko's SSHClient.connect() accepts a password parameter and performs password authentication, so using a username and password is perfectly valid. The authentication phase is encrypted by the SSH transport, so the credentials are not exposed as plaintext. Thus, the failure is not caused by an authentication method mismatch; the script gets past authentication but fails later at command execution.

  • ✓

    The script will fail because Cisco IOS does not support SSH command execution; it requires an interactive shell session.

    Why this is correct

    The failure occurs because Cisco IOS does not support the SSH exec channel that Paramiko's exec_command() uses; it expects a full interactive terminal session. When exec_command() sends a single command, IOS has no mechanism to run it directly and may close the channel or ignore it. The correct approach is invoke_shell(), which allocates a VTY session and lets the automation interact with the CLI prompts.

  • ✗

    The script will fail because the output should be read using stdout.readlines() instead of stdout.read().

    Why it's wrong here

    stdout.read() reads all data from the channel until EOF, and stdout.readlines() also works; neither is inherently correct or incorrect. Paramiko's Channel.makefile() provides a file-like object with both methods. Because the failure happens at the exec_command() call before any output is generated, changing to readlines() would not fix the script.

About these practice questions

This 350-401 question is part of Courseiva's 1,923-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 350-401 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 350-401 exam.