200-901 Software Development and Design Practice Question
A Python script is interacting with a REST API that returns JSON. The script needs to handle potential errors gracefully. Which TWO practices should be implemented? (Choose two.)
⚠ Common exam trap
Cisco often tests the distinction between using `response.raise_for_status()` versus manually checking `response.status_code` — the trap is that candidates think only one is correct, but both are valid and complementary practices for robust error handling.
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
✓
Use response.raise_for_status() to raise exceptions for HTTP errors.
Option A is correct because response.raise_for_status() from the requests library inspects the HTTP status code and raises an HTTPError for 4xx and 5xx responses, letting the script handle failures via try/except instead of silently processing bad data. Option C is correct because explicitly checking response.status_code (e.g., comparing against 200 or using 200 <= status_code < 300) lets the script branch on success or failure and decide whether to parse JSON or handle the error, which is essential for graceful error handling. Option B is not appropriate because a single undifferentiated try/except hides the specific cause of failures and prevents tailored handling of HTTP errors, JSON decode errors, or connection issues. Option D is wrong because assuming requests always succeed ignores network failures, timeouts, and 4xx/5xx responses, which defeats graceful error handling. Option E is wrong because calling json.loads() unconditionally can raise JSONDecodeError on non-JSON bodies (e.g., HTML error pages), so parsing should occur only after confirming a successful, JSON content-type response.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Use response.raise_for_status() to raise exceptions for HTTP errors.
Why this is correct
Using `response.raise_for_status()` converts 4xx and 5xx HTTP status codes into `HTTPError` exceptions, satisfying the stem's requirement to handle API errors gracefully rather than silently processing failed responses. This lets the script catch failures explicitly instead of parsing error payloads as valid JSON data.
- ✗
Use a single try/except block to catch all exceptions without differentiation.
Why it's wrong here
Catching every exception in one block discards the distinction between HTTP status errors, JSON decode failures and connection timeouts, so recovery logic cannot differ per failure. Separate handlers let each be retried, logged or surfaced appropriately. A single catch-all suits scripts where any failure triggers identical abort behaviour.
- ✓
Check response.status_code to determine success or failure.
Why this is correct
Inspecting `response.status_code` lets the script branch on the HTTP status class — 2xx success versus 4xx client or 5xx server errors — before parsing JSON, satisfying the requirement to handle API failures gracefully rather than crashing on unexpected payloads.
- ✗
Assume the request always succeeds; errors are rare.
Why it's wrong here
Assuming success leaves no handler for HTTP error codes, malformed JSON or socket timeouts, so the script crashes on the first failure. Graceful handling requires explicit try/except around the request and parsing. This assumption only holds for controlled internal calls where failures genuinely cannot occur.
- ✗
Always parse the response body with json.loads() regardless of content type.
Why it's wrong here
Calling json.loads() on an HTML error page or empty body raises JSONDecodeError, masking the real HTTP failure. The Content-Type header or response status should gate parsing. Unconditional parsing is fine only when the endpoint contract guarantees JSON on every response, including errors.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 200-901 question from scratch — 975 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 →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 200-901 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 200-901 exam.