Handling API errors
Check a response's status code (200 OK, 404 not found) and wrap requests.get() in try/except so a failed API call shows a friendly message, not a crash.
Understanding Handling API errors in VCE Software Development U4O1
What it does: This branch tests for the 404 not found code, so the program can show a message instead of using data that does not exist. The call that might fail goes inside try, so if it raises an exception the except block runs and the program keeps going. 200 means OK: the server found the data and sent it back. 404 means the resource was not found. Use == to compare. A single = is assignment and causes a syntax error in an if statement. A friendly message is clear and tells the user what to do. Raw error text confuses users and is poor feedback.
Common mistakes: A single = assigns a value and is a syntax error in an if condition. Use == to compare the status code with 200. The except line must end with a colon. It should be except requests.Timeout:.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 115–124) and word search (Modules 115–171).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
response.status_codeFill in the Blanks
Spot the Error
Student with a class code? Join your class →