Bird
0
0

Find the bug in this Flask code that tries to send a 302 redirect:

medium📝 Debug Q7 of 15
Rest API - HTTP Status Codes
Find the bug in this Flask code that tries to send a 302 redirect:
@app.route('/go')
def go():
    response = Response('Redirecting', status=302)
    response.headers['Location'] = '/new'
    return response
AResponse body should be empty for redirects
BStatus code 302 is incorrect for redirect
CLocation header must be set before creating Response
DFlask redirect() function should be used instead
Step-by-Step Solution
Solution:
  1. Step 1: Understand redirect response body

    Redirect responses usually have empty body or minimal content; body text is ignored by clients.
  2. Step 2: Identify issue with non-empty body

    The code sets a non-empty body ('Redirecting'), but for proper redirects the response body should be empty.
  3. Final Answer:

    Response body should be empty for redirects -> Option A
  4. Quick Check:

    Redirects usually have empty response body [OK]
Quick Trick: Redirect responses typically have empty body [OK]
Common Mistakes:
  • Including unnecessary body text in redirect response
  • Confusing status codes for redirect
  • Thinking Location header must be set before Response object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes