Bird
0
0

You wrote this code to send a Bearer token but the server always responds with 401 Unauthorized. What is the likely error?

medium📝 Debug Q14 of 15
Rest API - Authentication and Authorization
You wrote this code to send a Bearer token but the server always responds with 401 Unauthorized. What is the likely error?
headers = {"Authorization": "bearer mytoken123"}
response = requests.get(url, headers=headers)
AThe URL is incorrect
BThe token string is missing
CThe header name should be 'Token' instead of 'Authorization'
DThe word 'bearer' should be capitalized as 'Bearer'
Step-by-Step Solution
Solution:
  1. Step 1: Check Bearer token header case sensitivity

    The 'Bearer' keyword in the Authorization header is case sensitive and must be capitalized.
  2. Step 2: Identify the error in the code

    The code uses 'bearer' in lowercase, causing the server to reject the token and respond 401.
  3. Final Answer:

    The word 'bearer' should be capitalized as 'Bearer' -> Option D
  4. Quick Check:

    Bearer keyword is case sensitive [OK]
Quick Trick: Capitalize 'Bearer' exactly in Authorization header [OK]
Common Mistakes:
  • Using lowercase 'bearer' keyword
  • Changing header name from 'Authorization'
  • Ignoring token format errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes