Consider this Python code snippet running on a Raspberry Pi to start a simple HTTPS server using http.server and ssl modules. What will it print when started successfully?
import http.server import ssl server_address = ('', 4443) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True) print('Serving on https://localhost:4443') httpd.serve_forever()
Look at the print statement and the port used.
The code explicitly prints 'Serving on https://localhost:4443' before starting the server. The server uses SSL on port 4443, so the URL is HTTPS and localhost.
To enable HTTPS on a Raspberry Pi web server, which file must you have to provide the server's identity securely?
Think about what HTTPS needs to prove the server's identity.
HTTPS requires a certificate file (often combined with a private key) like server.pem to encrypt communication and prove the server's identity.
Look at this Python code snippet for an HTTPS server on Raspberry Pi. It raises an error when run. What is the cause?
import http.server import ssl server_address = ('', 4443) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='server.key', certfile='server.crt', server_side=True) httpd.serve_forever()
Check the SSL wrapping parameters and file requirements.
The ssl.wrap_socket function requires the private key and certificate to be correctly provided. Often, the key and cert must be combined into one PEM file or correctly referenced. If separate files are used, they must exist and be valid. Missing or mismatched files cause errors.
Choose the correct Python code snippet that creates an SSL context for an HTTPS server on Raspberry Pi.
Look for the protocol designed for servers.
ssl.PROTOCOL_TLS_SERVER is the correct protocol for creating an SSL context for a server. Other protocols like SSLv3 are outdated or for clients.
Given this Python HTTPS server code running on Raspberry Pi, how many simultaneous HTTPS client connections can it handle by default?
import http.server import ssl server_address = ('', 4443) httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, certfile='server.pem', server_side=True) httpd.serve_forever()
Consider the default behavior of http.server.HTTPServer.
The http.server.HTTPServer class is single-threaded and handles one request at a time by default. To handle multiple simultaneous connections, you need to use ThreadingHTTPServer or similar.