Complete the code to start a simple HTTPS server using Python's http.server module.
import http.server import ssl server_address = ('localhost', 4443) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='[1]', certfile='server.pem', server_side=True) httpd.serve_forever()
The keyfile parameter requires the private key file, commonly named server.key.
Complete the command to generate a self-signed certificate using OpenSSL.
openssl req -x509 -newkey rsa:4096 -keyout [1] -out server.pem -days 365 -nodes
The -keyout option specifies the filename for the private key, commonly server.key.
Fix the error in the Python code to correctly wrap the socket for HTTPS.
import http.server import ssl httpd = http.server.HTTPServer(('0.0.0.0', 4443), http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', keyfile=[1], server_side=True) httpd.serve_forever()
The keyfile parameter must be a string with the filename in quotes, like 'server.key'.
Fill both blanks to create a dictionary comprehension that maps domain names to their certificate expiration days.
cert_days = {domain: [1] for domain, cert in certs.items() if cert.[2] > 0}The dictionary comprehension uses cert.expiration_days to get days and checks if cert.expiry is positive.
Fill all three blanks to create a secure HTTPS server setup with certificate and key files.
import http.server import ssl server_address = ('', 443) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=[1], certfile=[2], server_side=[3]) httpd.serve_forever()
The keyfile is the private key file 'server.key', the certfile is the certificate file 'server.pem', and server_side must be True to enable server mode.