Complete the code to add the Authorization header for Basic authentication.
headers = {"Authorization": "Basic [1]"}The Authorization header for Basic authentication requires the username and password encoded in base64 as a UTF-8 string.
Complete the code to create the Basic authentication header value correctly.
auth_value = "Basic " + [1]
The credentials must be base64 encoded from bytes and then decoded to a UTF-8 string before adding to the header.
Fix the error in the code to correctly set the Basic authentication header.
import base64 credentials = 'admin:1234' encoded = base64.b64encode([1]) headers = {'Authorization': 'Basic ' + encoded.decode('utf-8')}
The string credentials must be converted to bytes before base64 encoding.
Fill both blanks to create a Basic authentication header with username and password.
import base64 user = 'user1' passw = 'pass1' creds = f"[1]:[2]" encoded = base64.b64encode(creds.encode('utf-8')).decode('utf-8') headers = {'Authorization': 'Basic ' + encoded}
The credentials string must be username and password joined by a colon.
Fill all three blanks to build a Basic authentication header from variables and encode it properly.
import base64 username = 'alice' password = 'wonderland' credentials = f"[1]:[2]" encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode([3]) headers = {'Authorization': 'Basic ' + encoded_credentials}
The credentials string is username and password joined by a colon. The encoded bytes are decoded using 'utf-8' to get a string for the header.