Bird
0
0

A developer wrote this code to start a long-running task and check its status:

medium📝 Debug Q14 of 15
Rest API - Advanced Patterns
A developer wrote this code to start a long-running task and check its status:
response = start_task()
if response.status_code == 202:
    status_url = response.json()["status_url"]
    result = requests.post(status_url)
    print(result.json())

What is the error in this code?
AUsing POST instead of GET to check the status URL.
BNot checking if status_url exists in the response.
CNot handling the case when status_code is not 202.
DPrinting result without parsing JSON.
Step-by-Step Solution
Solution:
  1. Step 1: Review HTTP method used to check status

    The code uses POST to check status, but status URLs require GET requests.
  2. Step 2: Confirm other parts of code

    Checking status_url existence and status_code handling are good practices but not the main error here.
  3. Final Answer:

    Using POST instead of GET to check the status URL. -> Option A
  4. Quick Check:

    Status check = GET, not POST [OK]
Quick Trick: Status check always uses GET method [OK]
Common Mistakes:
MISTAKES
  • Using POST instead of GET for status check
  • Ignoring missing status_url key
  • Not handling unexpected status codes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes