Connections - urllib3 1.26.18 documentation

Hide navigation sidebar
Hide table of contents sidebar
Support urllib3 on GitHub Sponsors
Back to top
Toggle table of contents sidebar

# Connections

class urllib3.connection.HTTPConnection(*args, **kw)

  Bases: `HTTPConnection`, `object`

  Based on `http.client.HTTPConnection` but provides an extra constructor backwards-compatibility layer between older and newer Pythons.

  Additional keyword parameters are used to configure attributes of the connection. Accepted parameters include:

  - `strict`: See the documentation on `urllib3.connectionpool.HTTPConnectionPool`

  - `source_address`: Set the source address for the current connection.

  - `socket_options`: Set specific options on the underlying socket. If not specified, then defaults are loaded from `HTTPConnection.default_socket_options` which includes disabling Nagle’s algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.

    For example, if you wish to enable TCP Keep Alive in addition to the defaults, you might pass:

        HTTPConnection.default_socket_options + [
            (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
        ]

    Or you may want to disable the defaults by passing an empty list (e.g., `[]`).

  connect()

    Connect to the host and port specified in __init__.

  default_socket_options = [(6, 1, 1)]

    Disable Nagle’s algorithm by default. `[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]`

  property host

    Getter method to remove any trailing dots that indicate the hostname is an FQDN.

    In general, SSL certificates don’t include the trailing dot indicating a fully-qualified domain name, and thus, they don’t validate properly when checked against a domain name that includes the dot. In addition, some servers may not expect to receive the trailing dot when provided.

    However, the hostname with trailing dot is critical to DNS resolution; doing a lookup with the trailing dot will properly only resolve the appropriate FQDN, whereas a lookup without a trailing dot will search the system’s search domain list. Thus, it’s important to keep the original host around for use only in those cases where it’s appropriate (i.e., when doing DNS lookup to establish the actual TCP connection across which we’re going to send HTTP requests).

  is_verified = False

    Whether this connection verifies the host’s certificate.

  proxy_is_verified = None

    Whether this proxy connection (if used) verifies the proxy host’s certificate.

  request(method, url, body=None, headers=None)

    Send a complete request to the server.

  request_chunked(method, url, body=None, headers=None)

    Alternative to the common request method, which sends the body with chunked encoding and not as one block

  socket_options

    The socket options provided by the user. If no options are provided, we use the default options.

class urllib3.connection.HTTPSConnection(host, port=None, key_file=None, cert_file=None, key_password=None, strict=None, timeout=<object object>, ssl_context=None, server_hostname=None, **kw)

  Bases: `HTTPConnection`

  Many of the parameters to this constructor are passed to the underlying SSL socket by means of `urllib3.util.ssl_wrap_socket()`.

  connect()

    Connect to the host and port specified in __init__.

  set_cert(key_file=None, cert_file=None, cert_reqs=None, key_password=None, ca_certs=None, assert_hostname=None, assert_fingerprint=None, ca_cert_dir=None, ca_cert_data=None)

    This method should only be called once, before the connection is used.