Bird
0
0

What is the issue with this Flask health check endpoint code?

medium📝 Debug Q6 of 15
Flask - Deployment
What is the issue with this Flask health check endpoint code?
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/health')
def health():
    return jsonify({'status': 'ok'})
AMissing return status code in the response
Bjsonify should be called with keyword arguments, not a dictionary
CThe route decorator is missing parentheses
DFlask app instance is not created properly
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of jsonify

    jsonify expects keyword arguments or a list, not a dictionary as a single positional argument.
  2. Step 2: Identify correct usage

    Correct usage is jsonify(status='ok') instead of jsonify({'status': 'ok'}).
  3. Final Answer:

    jsonify should be called with keyword arguments, not a dictionary -> Option B
  4. Quick Check:

    Verify jsonify argument types [OK]
Quick Trick: jsonify accepts kwargs, not dict as single argument [OK]
Common Mistakes:
MISTAKES
  • Passing a dict directly to jsonify
  • Ignoring Flask's jsonify argument requirements
  • Assuming jsonify accepts any object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes