Bases: RequestMethods
Allows for arbitrary requests while transparently keeping track of necessary connection pools for you.
num_pools – Number of connection pools to cache before discarding the least recently used pool.
headers – Headers to include with all requests, unless other headers are given explicitly.
**connection_pool_kw – Additional parameters are used to create fresh
urllib3.connectionpool.ConnectionPool
instances.
Example:
import urllib3
http = urllib3.PoolManager(num_pools=2)
resp1 = http.request("GET", "https://google.com/")
resp2 = http.request("GET", "https://google.com/mail")
resp3 = http.request("GET", "https://yahoo.com/")
print(len(http.pools))
# 2
Empty our store of pools and direct them all to close.
This will not affect in-flight connections, but they will not be re-used after completion.
Get a urllib3.connectionpool.ConnectionPool
based on the request context.
request_context
must at least contain the scheme
key and its
value must be a key in key_fn_by_scheme
instance variable.
Get a urllib3.connectionpool.ConnectionPool
based on the host, port, and scheme.
If port
isn’t given, it will be derived from the scheme
using
urllib3.connectionpool.port_by_scheme
. If pool_kwargs
is
provided, it is merged with the instance’s connection_pool_kw
variable and used to create the new connection pool, if one is
needed.
Get a urllib3.connectionpool.ConnectionPool
based on the provided pool key.
pool_key
should be a namedtuple that only contains immutable
objects. At a minimum it must have the scheme
, host
, and
port
fields.
Similar to urllib3.connectionpool.connection_from_url()
.
If pool_kwargs
is not provided and a new pool needs to be
constructed, self.connection_pool_kw
is used to initialize
the urllib3.connectionpool.ConnectionPool
. If pool_kwargs
is provided, it is used instead. Note that if a new pool does not
need to be created for the request, the provided pool_kwargs
are
not used.
Same as urllib3.HTTPConnectionPool.urlopen()
with custom cross-host redirect logic and only sends the request-uri
portion of the url
.
The given url
parameter must be absolute, such that an appropriate
urllib3.connectionpool.ConnectionPool
can be chosen for it.
Bases: PoolManager
Behaves just like PoolManager
, but sends all requests through
the defined proxy, using the CONNECT method for HTTPS URLs.
proxy_url – The URL of the proxy to be used.
proxy_headers – A dictionary containing headers that will be sent to the proxy. In case of HTTP they are being sent with each request, while in the HTTPS/CONNECT case they are sent only once. Could be used for proxy authentication.
proxy_ssl_context – The proxy SSL context is used to establish the TLS connection to the proxy when using HTTPS proxies.
use_forwarding_for_https – (Defaults to False) If set to True will forward requests to the HTTPS proxy to be made on behalf of the client instead of creating a TLS tunnel via the CONNECT method. Enabling this flag means that request and response headers and content will be visible from the HTTPS proxy whereas tunneling keeps request and response headers and content private. IP address, target hostname, SNI, and port are always visible to an HTTPS proxy even when this flag is disabled.
proxy_assert_hostname – The hostname of the certificate to verify against.
proxy_assert_fingerprint – The fingerprint of the certificate to verify against.
Example:
import urllib3
proxy = urllib3.ProxyManager("https://localhost:3128/")
resp1 = proxy.request("GET", "https://google.com/")
resp2 = proxy.request("GET", "https://httpbin.org/")
print(len(proxy.pools))
# 1
resp3 = proxy.request("GET", "https://httpbin.org/")
resp4 = proxy.request("GET", "https://twitter.com/")
print(len(proxy.pools))
# 3
Get a urllib3.connectionpool.ConnectionPool
based on the host, port, and scheme.
If port
isn’t given, it will be derived from the scheme
using
urllib3.connectionpool.port_by_scheme
. If pool_kwargs
is
provided, it is merged with the instance’s connection_pool_kw
variable and used to create the new connection pool, if one is
needed.