Bird
Raised Fist0

Identify the issue in this Python code snippet using the requests library:

medium📝 Debug Q7 of Q15
Rest API - Authentication and Authorization
Identify the issue in this Python code snippet using the requests library:
headers = {"Authorization": "Bearer" + token}
response = requests.get(url, headers=headers)
AMissing space between 'Bearer' and the token in the Authorization header
BIncorrect HTTP method used; should be POST instead of GET
CHeaders dictionary should be named 'header' not 'headers'
DToken variable should be enclosed in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Review the Authorization header format

    The 'Bearer' keyword must be followed by a space before the token.
  2. Step 2: Analyze the code

    The code concatenates 'Bearer' and token without a space, resulting in an invalid header.
  3. Final Answer:

    Missing space between 'Bearer' and the token in the Authorization header -> Option A
  4. Quick Check:

    Check for space after 'Bearer' in header string [OK]
Quick Trick: Add a space after 'Bearer' before token [OK]
Common Mistakes:
MISTAKES
  • Concatenating without space
  • Using wrong HTTP method
  • Misnaming headers dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes