Bird
Raised Fist0

What will be the output of this simplified token exchange request in Python if the authorization code is invalid?

medium📝 Predict Output Q4 of Q15
Rest API - Authentication and Authorization
What will be the output of this simplified token exchange request in Python if the authorization code is invalid?
import requests
response = requests.post('https://auth.example.com/token', data={'code': 'invalid_code', 'grant_type': 'authorization_code'})
print(response.status_code)
A200
B302
C400
D500
Step-by-Step Solution
Solution:
  1. Step 1: Understand token exchange error handling

    If the authorization code is invalid, the server responds with a client error status code indicating bad request.
  2. Step 2: Identify correct HTTP status code

    400 Bad Request is the standard response for invalid or malformed requests.
  3. Final Answer:

    400 -> Option C
  4. Quick Check:

    Invalid code response = 400 Bad Request [OK]
Quick Trick: Invalid code causes 400 Bad Request response [OK]
Common Mistakes:
MISTAKES
  • Expecting 200 OK despite invalid code
  • Confusing 302 redirect with token response
  • Assuming server error 500 for client mistakes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes