should_bypass_proxies() — requests Function Reference
Architecture documentation for the should_bypass_proxies() function in utils.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD c32589ad_d9fc_2a46_ebec_d0e98c4eb814["should_bypass_proxies()"] 2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c 2ab09f20_2415_ca33_54ea_ec124645ba35["get_environ_proxies()"] 2ab09f20_2415_ca33_54ea_ec124645ba35 -->|calls| c32589ad_d9fc_2a46_ebec_d0e98c4eb814 78f79a1e_c8bc_1d85_cefa_cf45d6efb42a["resolve_proxies()"] 78f79a1e_c8bc_1d85_cefa_cf45d6efb42a -->|calls| c32589ad_d9fc_2a46_ebec_d0e98c4eb814 48dec9f1_c75c_5c4c_bec3_d3ede1d48ba4["is_ipv4_address()"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|calls| 48dec9f1_c75c_5c4c_bec3_d3ede1d48ba4 50bcc56d_2b44_d21c_8d0b_bee80b09ab48["is_valid_cidr()"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|calls| 50bcc56d_2b44_d21c_8d0b_bee80b09ab48 34b0e954_f61f_4779_0ea3_62759d4a4f26["address_in_network()"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|calls| 34b0e954_f61f_4779_0ea3_62759d4a4f26 e8cea911_4391_96da_8be8_0819dbefec5c["set_environ()"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|calls| e8cea911_4391_96da_8be8_0819dbefec5c 3429da06_bfa7_f55e_ca34_e7199d2cf1df["get()"] c32589ad_d9fc_2a46_ebec_d0e98c4eb814 -->|calls| 3429da06_bfa7_f55e_ca34_e7199d2cf1df style c32589ad_d9fc_2a46_ebec_d0e98c4eb814 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/utils.py lines 753–811
def should_bypass_proxies(url, no_proxy):
"""
Returns whether we should bypass proxies or not.
:rtype: bool
"""
# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
def get_proxy(key):
return os.environ.get(key) or os.environ.get(key.upper())
# First check whether no_proxy is defined. If it is, check that the URL
# we're getting isn't in the no_proxy list.
no_proxy_arg = no_proxy
if no_proxy is None:
no_proxy = get_proxy("no_proxy")
parsed = urlparse(url)
if parsed.hostname is None:
# URLs don't always have hostnames, e.g. file:/// urls.
return True
if no_proxy:
# We need to check whether we match here. We need to see if we match
# the end of the hostname, both with and without the port.
no_proxy = (host for host in no_proxy.replace(" ", "").split(",") if host)
if is_ipv4_address(parsed.hostname):
for proxy_ip in no_proxy:
if is_valid_cidr(proxy_ip):
if address_in_network(parsed.hostname, proxy_ip):
return True
elif parsed.hostname == proxy_ip:
# If no_proxy ip was defined in plain IP notation instead of cidr notation &
# matches the IP of the index
return True
else:
host_with_port = parsed.hostname
if parsed.port:
host_with_port += f":{parsed.port}"
for host in no_proxy:
if parsed.hostname.endswith(host) or host_with_port.endswith(host):
# The URL does match something in no_proxy, so we don't want
# to apply the proxies on this URL.
return True
with set_environ("no_proxy", no_proxy_arg):
# parsed.hostname can be `None` in cases such as a file URI.
try:
bypass = proxy_bypass(parsed.hostname)
except (TypeError, socket.gaierror):
bypass = False
if bypass:
return True
return False
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does should_bypass_proxies() do?
should_bypass_proxies() is a function in the requests codebase, defined in src/requests/utils.py.
Where is should_bypass_proxies() defined?
should_bypass_proxies() is defined in src/requests/utils.py at line 753.
What does should_bypass_proxies() call?
should_bypass_proxies() calls 5 function(s): address_in_network, get, is_ipv4_address, is_valid_cidr, set_environ.
What calls should_bypass_proxies()?
should_bypass_proxies() is called by 2 function(s): get_environ_proxies, resolve_proxies.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free