Complete the code to return the correct HTTP status code for unauthorized access.
return [1] # Status code for unauthorized access
The HTTP status code 401 Unauthorized means the user is not authenticated and must provide valid credentials.
Complete the code to return the correct HTTP status code for forbidden access.
return [1] # Status code for forbidden access
The HTTP status code 403 Forbidden means the user is authenticated but does not have permission to access the resource.
Fix the error in the code to correctly check if a user is authenticated before returning 401.
if not user.is_authenticated: return [1] # Correct status code for unauthorized
The code should return 401 Unauthorized when the user is not authenticated.
Fill both blanks to return 403 when user lacks permission and 401 when not authenticated.
if not user.is_authenticated: return [1] # Unauthorized elif not user.has_permission: return [2] # Forbidden
Use 401 for unauthenticated users and 403 for authenticated users without permission.
Fill all three blanks to create a function that returns 401 if not authenticated, 403 if forbidden, else 200.
def check_access(user): if not user.[1]: return [2] elif not user.[3]: return 403 else: return 200
The function checks if the user is authenticated (is_authenticated) and returns 401 if not. Then it checks if the user has permission (has_permission) and returns 403 if not. Otherwise, it returns 200 OK.