Courseiva
mediumMultiple Choice

350-401 Practice Question: Is writing a Python script to automate the backup…

A network engineer is writing a Python script to automate the backup of running configurations from a list of 50 Cisco IOS-XE devices. The script uses the netmiko library and a for loop to connect to each device, execute 'show run', and write the output to a file. After running the script, the engineer notices that the script fails on the 15th device with a timeout error, and the remaining devices are not processed. The engineer wants to ensure that if one device fails, the script continues with the next device. What is the best way to modify the script?

⚠ Common exam trap

Cisco often tests the distinction between handling exceptions (try-except) versus changing configuration (timeout) or parallelism (threading), and the trap here is that candidates may think increasing timeouts or using threads alone will solve the failure propagation issue without understanding that exception handling is required to continue execution after an error.

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

✓

Wrap the connection and backup logic inside a try-except block within the for loop.

Wrapping the connection and backup logic inside a try-except block within the for loop catches exceptions (such as netmiko's NetMikoTimeoutException) for each device individually. This allows the loop to continue processing the remaining devices after a failure, rather than aborting the entire script. The try-except pattern is the standard Python approach for handling runtime errors without breaking iterative processes.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Increase the global timeout value in the netmiko connection handler.

    Why it's wrong here

    Increasing the global timeout value in the netmiko connection handler only extends the duration netmiko waits before raising a timeout exception. It does not catch or suppress exceptions that occur due to immediate failures such as authentication errors, DNS resolution failures, or connection refused errors. A longer timeout could make the script hang on an unreachable device for a longer period, and the unhandled exception will still terminate the script at the exact same point once the timeout expires.

  • ✗

    Use the concurrent.futures module to run each connection in a separate thread.

    Why it's wrong here

    The concurrent.futures module runs each connection in a separate thread, but multithreading provides no implicit exception containment. If any thread raises an unhandled exception, the exception will be stored in that thread's Future object, and unless you explicitly call future.result() inside a try-except block, the exception may propagate and crash the entire script. Even with ThreadPoolExecutor, you must wrap the worker function in try-except, and you also introduce complexity like thread safety and resource limits, making this option an incomplete solution for the stated problem.

  • ✓

    Wrap the connection and backup logic inside a try-except block within the for loop.

    Why this is correct

    Wrapping the connection and backup logic inside a try-except block within the for loop directly addresses the failure point: each device's operations are executed in its own protected scope. When a device raises an exception (e.g., NetMikoTimeoutException or NetMikoAuthenticationException), the except clause catches it, allowing the script to log the error and continue with the next iteration. This pattern, often called 'fail-continue', ensures that a single unreachable or misconfigured device does not abort the backup process for all remaining devices, which is the core requirement of a resilient network automation script.

  • ✗

    Replace the for loop with a while loop that retries the connection three times before moving on.

    Why it's wrong here

    Replacing the for loop with a while loop that retries the connection three times does not prevent the script from stopping because it does not add any exception handling. On the first failed connection attempt, an unhandled exception is raised and immediately propagates out of the while loop, so the retry counter never increments and the retry logic never runs. To make retries work, you would still need to surround the connection attempt with try-except, and even then the except block would need to decide whether to continue the outer loop or break—thus retries are a complementary mechanism, not a substitute for catching exceptions.

About these practice questions

Courseiva writes every 350-401 question from scratch — 1,923 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.