Debugging When the Script Breaks
Lesson 10 of 10
The Scenario
Your config backup script was working perfectly for two weeks. Today it crashes with a NetmikoTimeoutException on one device and a ValueError: could not convert string to float on another. You do not need to understand Python debugging — you need AI to fix it.
The Pattern: Copy, Paste, Fix
When a script fails:
- Copy the entire error traceback
- Paste it into ChatGPT/Claude with the context
- Apply the fix
The Prompt
My Python script is crashing with this error. Fix it and explain what went wrong:
[paste the full traceback here]
The script is supposed to: [one sentence about what it does]
Here is the relevant code section: [paste the function that is failing]
Common Network Automation Errors and Fixes
NetmikoTimeoutException: Device is unreachable or SSH is not enabled
- AI fix: Add timeout parameter, wrap in try/except, skip to next device
NetmikoAuthenticationException: Wrong username/password
- AI fix: Verify credentials, check if device requires
enablepassword
ValueError during parsing: Show command output format changed between IOS versions
- AI fix: Make the regex/parser more flexible, handle edge cases
ConnectionResetError: Device closed the SSH session (often rate limiting)
- AI fix: Add delay between connections, reduce parallel sessions
UnicodeDecodeError: Device output contains special characters
- AI fix: Add
encoding=utf-8or handle encoding errors
Pro Tip: Prevent Before Debug
Ask AI to add error handling before you need it:
Review this script and add proper error handling:
- Handle connection timeouts per device (do not crash the whole script)
- Log errors to a file with the device name and timestamp
- Add a retry mechanism: try each device 3 times with 10 second delay
- Send a summary at the end: X succeeded, Y failed
[paste your script]
Try It Yourself
Take any script from a previous chapter. Intentionally break something (wrong IP, wrong credential, wrong command). Run it, copy the error, paste into AI, and apply the fix.
Subscribe to unlock this lesson
₹7,999/year
Full access to all 10 lessons in this course, plus 74 more lab courses, quizzes, and AI mock interviews. 365 days.
Already have an account? Sign in