Connections¶
- class urllib3.connection.HTTPConnection(host, port=None, *, timeout=_TYPE_DEFAULT.token, source_address=None, blocksize=131072, socket_options=[(6, 1, 1, 'tcp')], proxy=None, proxy_config=None, disabled_svn=None, preemptive_quic_cache=None, resolver=None, socket_family=AddressFamily.AF_UNSPEC)¶
Bases:
HfaceBackendBased on
urllib3.backend.BaseBackendbut 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:
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 fromHTTPConnection.default_socket_optionswhich 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.,
[]).
- Parameters:
host (str)
port (int | None)
timeout (_TYPE_TIMEOUT_INTERNAL)
blocksize (int)
socket_options (_TYPE_SOCKET_OPTIONS | None)
proxy (Url | None)
proxy_config (ProxyConfig | None)
disabled_svn (set[HttpVersion] | None)
preemptive_quic_cache (QuicPreemptiveCacheType | None)
resolver (BaseResolver | None)
socket_family (socket.AddressFamily)
- close()¶
End the connection, do some reinit, closing of fd, etc…
- Return type:
None
- getresponse(*, promise=None, police_officer=None, early_response_callback=None)¶
Get the response from the server.
If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by the response_class variable.
If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP response indicates that the connection should be closed, then it will be closed before the response is returned. When the connection is closed, the underlying socket is closed.
- Parameters:
promise (ResponsePromise | None)
police_officer (TrafficPolice[HTTPConnection] | None)
early_response_callback (Callable[[HTTPResponse], None] | None)
- Return type:
- property host: str¶
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).
- set_tunnel(host, port=None, headers=None, scheme='http')¶
Prepare the connection to set up a tunnel. Does NOT actually do the socket and http connect. Here host:port represent the target (final) server and not the intermediary.
- class urllib3.connection.HTTPSConnection(host, port=None, *, timeout=_TYPE_DEFAULT.token, source_address=None, blocksize=131072, socket_options=[(6, 1, 1, 'tcp')], disabled_svn=None, preemptive_quic_cache=None, resolver=None, socket_family=AddressFamily.AF_UNSPEC, proxy=None, proxy_config=None, cert_reqs=None, assert_hostname=None, assert_fingerprint=None, server_hostname=None, ssl_context=None, ca_certs=None, ca_cert_dir=None, ca_cert_data=None, ssl_minimum_version=None, ssl_maximum_version=None, ssl_version=None, cert_file=None, key_file=None, key_password=None, cert_data=None, key_data=None)¶
Bases:
HTTPConnectionMany of the parameters to this constructor are passed to the underlying SSL socket by means of
urllib3.util.ssl_wrap_socket().- Parameters:
host (str)
port (int | None)
timeout (_TYPE_TIMEOUT_INTERNAL)
blocksize (int)
socket_options (_TYPE_SOCKET_OPTIONS | None)
disabled_svn (set[HttpVersion] | None)
preemptive_quic_cache (QuicPreemptiveCacheType | None)
resolver (BaseResolver | None)
socket_family (socket.AddressFamily)
proxy (Url | None)
proxy_config (ProxyConfig | None)
assert_hostname (None | str | Literal[False])
assert_fingerprint (str | None)
server_hostname (str | None)
ssl_context (ssl.SSLContext | None)
ca_certs (str | None)
ca_cert_dir (str | None)
ssl_minimum_version (int | None)
ssl_maximum_version (int | None)
cert_file (str | None)
key_file (str | None)
key_password (str | None)
- class urllib3._typing.ProxyConfig(ssl_context, use_forwarding_for_https, assert_hostname, assert_fingerprint)¶
Bases:
NamedTuple- Parameters:
ssl_context (ssl.SSLContext | None)
use_forwarding_for_https (bool)
assert_hostname (None | str | Literal[False])
assert_fingerprint (str | None)
- ssl_context: ssl.SSLContext | None¶
Alias for field number 0