ITCertFoundryTechnical training system
← All ENCOR reference pages

CCNP ENCOR reference

Python & JSON for Network Automation Quick Reference

Reading Python tracebacks, core data structures, and valid JSON syntax — tested in ENCOR objectives 6.1–6.2.

Reading a traceback fast

Check the FINAL line first — it names the exception type (KeyError, IndexError, TypeError...) and a brief message, usually the fastest path to understanding what went wrong. The lines above show the call sequence that led there, useful for context but not the fastest starting point.

IndexError: accessing a list position that doesn't exist. KeyError: accessing a dictionary key that doesn't exist. Different exception types, different root causes.

A script that doesn't crash can still be wrong

Clean completion doesn't guarantee correct output — an off-by-one loop error or an unexpectedly reassigned variable can silently produce wrong results with no exception at all. Add a temporary print() before a suspect line to see the actual data.

Valid JSON, exactly

Double quotes only — for both keys and string values. Single quotes (valid in Python) are NOT valid JSON.

No trailing comma after the last item in an object or array — most parsers reject the whole payload.

Numbers and booleans (true/false, lowercase) are never quoted.

A malformed JSON payload is typically rejected before the server ever evaluates whether the actual data makes sense — validate syntax (python3 -m json.tool) before assuming the data content is the problem.

List vs. dictionary

ListDictionary
Access byNumeric position (index)Key
Syntax[ ]{ }
Missing-item errorIndexErrorKeyError