Home / Function/ get_connection() — requests Function Reference

get_connection() — requests Function Reference

Architecture documentation for the get_connection() function in adapters.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  a177b992_27e6_4822_1c3a_48567aa04e20["get_connection()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91["HTTPAdapter"]
  a177b992_27e6_4822_1c3a_48567aa04e20 -->|defined in| 5fdf5d52_8295_768a_e20f_c6cefb721b91
  4e2f0f8e_636e_37d3_f714_243f18338137["proxy_manager_for()"]
  a177b992_27e6_4822_1c3a_48567aa04e20 -->|calls| 4e2f0f8e_636e_37d3_f714_243f18338137
  60571fa2_2c29_a402_f268_a16ac679a1da["select_proxy()"]
  a177b992_27e6_4822_1c3a_48567aa04e20 -->|calls| 60571fa2_2c29_a402_f268_a16ac679a1da
  9e0e1cd7_43e2_1740_9ce8_96012bdf42f7["prepend_scheme_if_needed()"]
  a177b992_27e6_4822_1c3a_48567aa04e20 -->|calls| 9e0e1cd7_43e2_1740_9ce8_96012bdf42f7
  style a177b992_27e6_4822_1c3a_48567aa04e20 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/adapters.py lines 474–513

    def get_connection(self, url, proxies=None):
        """DEPRECATED: Users should move to `get_connection_with_tls_context`
        for all subclasses of HTTPAdapter using Requests>=2.32.2.

        Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        """
        warnings.warn(
            (
                "`get_connection` has been deprecated in favor of "
                "`get_connection_with_tls_context`. Custom HTTPAdapter subclasses "
                "will need to migrate for Requests>=2.32.2. Please see "
                "https://github.com/psf/requests/pull/6710 for more details."
            ),
            DeprecationWarning,
        )
        proxy = select_proxy(url, proxies)

        if proxy:
            proxy = prepend_scheme_if_needed(proxy, "http")
            proxy_url = parse_url(proxy)
            if not proxy_url.host:
                raise InvalidProxyURL(
                    "Please check proxy URL. It is malformed "
                    "and could be missing the host."
                )
            proxy_manager = self.proxy_manager_for(proxy)
            conn = proxy_manager.connection_from_url(url)
        else:
            # Only scheme should be lower case
            parsed = urlparse(url)
            url = parsed.geturl()
            conn = self.poolmanager.connection_from_url(url)

        return conn

Domain

Subdomains

Frequently Asked Questions

What does get_connection() do?
get_connection() is a function in the requests codebase, defined in src/requests/adapters.py.
Where is get_connection() defined?
get_connection() is defined in src/requests/adapters.py at line 474.
What does get_connection() call?
get_connection() calls 3 function(s): prepend_scheme_if_needed, proxy_manager_for, select_proxy.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free