Bird
0
0

You have this code snippet to send an API key in a URL parameter:

medium📝 Debug Q14 of 15
Rest API - Authentication and Authorization
You have this code snippet to send an API key in a URL parameter:
import requests
url = "https://api.example.com/data?api_key=12345"
response = requests.get(url)
print(response.status_code)
The server always returns 401 Unauthorized. What is the most likely problem?
AThe API key value is incorrect
BThe URL is missing HTTPS
CThe API key should be sent in headers, not URL parameters
DThe requests library does not support URL parameters
Step-by-Step Solution
Solution:
  1. Step 1: Check if sending API key in URL is allowed

    Many APIs accept API keys in URL parameters, so this is often valid.
  2. Step 2: Consider the 401 Unauthorized response

    401 usually means invalid or missing credentials, so the key value is likely wrong.
  3. Final Answer:

    The API key value is incorrect -> Option A
  4. Quick Check:

    401 = Invalid credentials [OK]
Quick Trick: 401 usually means wrong or missing API key value [OK]
Common Mistakes:
  • Assuming URL parameters never work for API keys
  • Ignoring that 401 means invalid credentials
  • Thinking requests library can't send URL parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes