Python Glossary Русский

Python 3.14+http.serverterm

http.server.HTTPSServer

servers

An HTTPServer with TLS: it takes certfile and keyfile and serves HTTPS. Added in Python 3.14.

Syntax

HTTPSServer(server_address, Handler, bind_and_activate=True, *, certfile, keyfile=None, password=None, alpn_protocols=None)

certfile is a required keyword argument; without it you get TypeError. The certificate is read not in the constructor but when the socket is activated (server_activate), so with bind_and_activate=False a wrong path surfaces later, at start-up. By default ALPN advertises only http/1.1. Before 3.14 the same was done by hand with ssl.SSLContext.wrap_socket over server.socket.

Examples

from http.server import HTTPSServer, BaseHTTPRequestHandler
srv = HTTPSServer(('127.0.0.1', 8443), BaseHTTPRequestHandler,
                  bind_and_activate=False, certfile='missing.pem')
print(srv.certfile, srv.alpn_protocols)  # → missing.pem ['http/1.1']
srv.server_close()
try:
    HTTPSServer(('127.0.0.1', 8443), BaseHTTPRequestHandler, bind_and_activate=False)
except TypeError as e:
    print('TypeError')  # → TypeError — certfile обязателен

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy