Bird
0
0

Given this code snippet, what will be the output of print(token)?

medium📝 component behavior Q4 of 15
FastAPI - Authentication and Security
Given this code snippet, what will be the output of print(token)?
from jose import jwt
payload = {"user_id": 123}
secret = "mysecret"
token = jwt.encode(payload, secret, algorithm="HS256")
print(token)
AA string representing the encoded JWT token
BA dictionary with user_id key
CAn error because jose.jwt has no encode method
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand jose.jwt.encode behavior

    The jose library's jwt.encode returns a string JWT token from the payload and secret.
  2. Step 2: Analyze print output

    Printing token outputs the encoded JWT string, not a dictionary or error.
  3. Final Answer:

    A string representing the encoded JWT token -> Option A
  4. Quick Check:

    jwt.encode output = encoded JWT string [OK]
Quick Trick: jwt.encode returns a token string, not a dict or error [OK]
Common Mistakes:
MISTAKES
  • Expecting a dictionary output
  • Assuming encode method does not exist
  • Thinking output is None

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes