PyDocs

Nav

Internet Protocols and Support

HTTPSConnection

http.client

class (source) not WASI
  • HTTPSConnection(host, port=None, *, [timeout, ]source_address=None, context=None, blocksize=8192, max_response_headers=None)
This class allows communication via SSL.
Changed in 3.2, 3.4, 3.4.3, 3.8, 3.10, 3.12, 3.15
  • 3.2: source_address, context and check_hostname were added.
  • 3.2: This class now supports HTTPS virtual hosts if possible (that is, if ssl.HAS_SNI is true).
  • 3.4: The strict parameter was removed. HTTP 0.9-style “Simple Responses” are no longer supported.
  • 3.4.3: This class now performs all the necessary certificate and hostname checks by default. To revert to the previous, unverified, behavior ssl._create_unverified_context() can be passed to the context parameter.
  • 3.8: This class now enables TLS 1.3 ssl.SSLContext.post_handshake_auth for the default context or when cert_file is passed with a custom context.
  • 3.10: This class now sends an ALPN extension with protocol indicator http/1.1 when no context is given. Custom context should set ALPN protocols with set_alpn_protocols().
  • 3.12: The deprecated key_file, cert_file and check_hostname parameters have been removed.
  • 3.15: max_response_headers parameter was added.
1 Example
>>> import http.client
>>> conn = http.client.HTTPSConnection("www.python.org")
>>> conn.request("GET", "/")
>>> r1 = conn.getresponse()
>>> print(r1.status, r1.reason)
200 OK
>>> data1 = r1.read()  # This will return entire content.
>>> # The following example demonstrates reading data in chunks.
>>> conn.request("GET", "/")
>>> r1 = conn.getresponse()
>>> while chunk := r1.read(200):
...     print(repr(chunk))
b'<!doctype html>\n<!--[if"...
...
>>> # Example of an invalid request
>>> conn = http.client.HTTPSConnection("docs.python.org")
>>> conn.request("GET", "/parrot.spam")
>>> r2 = conn.getresponse()
>>> print(r2.status, r2.reason)
404 Not Found
>>> data2 = r2.read()
>>> conn.close()
from the Python docs
See Also
No see-alsos for http.client/HTTPSConnection
0 Notes
No notes for HTTPSConnection