Bird
0
0

You have this Python Flask endpoint:

medium📝 Debug Q6 of 15
Rest API - HTTP Status Codes
You have this Python Flask endpoint:
@app.route('/info')
def info():
    data = get_data()
    return jsonify(data)

Sometimes this returns a 500 error. What is a likely cause?
AThe jsonify function is not imported.
BThe client sends a bad request.
CThe route URL is incorrect.
DThe get_data() function raises an exception not handled.
Step-by-Step Solution
Solution:
  1. Step 1: Identify cause of 500 errors

    500 errors happen when server code throws exceptions not caught.
  2. Step 2: Analyze code snippet

    If get_data() raises an exception, Flask returns 500 unless handled.
  3. Final Answer:

    The get_data() function raises an exception not handled. -> Option D
  4. Quick Check:

    Unhandled exceptions in server code cause 500 errors [OK]
Quick Trick: Unhandled exceptions in server functions cause 500 errors [OK]
Common Mistakes:
  • Blaming client requests for 500 errors
  • Assuming route URL errors cause 500
  • Ignoring missing imports causing different errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes