Bird
0
0

Given this integration test snippet:

medium📝 Debug Q6 of 15
Rest API - API Testing and Monitoring
Given this integration test snippet:
response = requests.get('https://api.example.com/info')
print(response.json()['data'])

The test raises a KeyError. What is the most probable reason?
AThe URL is incorrect and returns 404
BThe JSON response does not contain the key 'data'
CThe requests library is not imported
DThe response status code is 500
Step-by-Step Solution
Solution:
  1. Step 1: Understand KeyError cause

    KeyError occurs when accessing a missing key in a dictionary.
  2. Step 2: Analyze response.json()

    If 'data' key is missing in the JSON, accessing it causes KeyError.
  3. Final Answer:

    The JSON response does not contain the key 'data' -> Option B
  4. Quick Check:

    Missing JSON keys cause KeyError, not HTTP errors [OK]
Quick Trick: KeyError means missing key in JSON response [OK]
Common Mistakes:
MISTAKES
  • Assuming HTTP errors cause KeyError
  • Ignoring the actual JSON structure
  • Not checking response status before accessing JSON

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes