get_netrc_auth() — requests Function Reference
Architecture documentation for the get_netrc_auth() function in utils.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD c7dd921b_c760_ae2b_9620_0ab18f3fcf42["get_netrc_auth()"] 2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"] c7dd921b_c760_ae2b_9620_0ab18f3fcf42 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c 18349e5e_3ab4_19be_23d5_20c1111b761b["rebuild_auth()"] 18349e5e_3ab4_19be_23d5_20c1111b761b -->|calls| c7dd921b_c760_ae2b_9620_0ab18f3fcf42 a4eb532d_c481_9e3e_ad07_8d203ffafd2d["prepare_request()"] a4eb532d_c481_9e3e_ad07_8d203ffafd2d -->|calls| c7dd921b_c760_ae2b_9620_0ab18f3fcf42 3429da06_bfa7_f55e_ca34_e7199d2cf1df["get()"] c7dd921b_c760_ae2b_9620_0ab18f3fcf42 -->|calls| 3429da06_bfa7_f55e_ca34_e7199d2cf1df style c7dd921b_c760_ae2b_9620_0ab18f3fcf42 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/utils.py lines 205–246
def get_netrc_auth(url, raise_errors=False):
"""Returns the Requests tuple auth for a given url from netrc."""
netrc_file = os.environ.get("NETRC")
if netrc_file is not None:
netrc_locations = (netrc_file,)
else:
netrc_locations = (f"~/{f}" for f in NETRC_FILES)
try:
from netrc import NetrcParseError, netrc
netrc_path = None
for f in netrc_locations:
loc = os.path.expanduser(f)
if os.path.exists(loc):
netrc_path = loc
break
# Abort early if there isn't one.
if netrc_path is None:
return
ri = urlparse(url)
host = ri.hostname
try:
_netrc = netrc(netrc_path).authenticators(host)
if _netrc:
# Return with login / password
login_i = 0 if _netrc[0] else 1
return (_netrc[login_i], _netrc[2])
except (NetrcParseError, OSError):
# If there was a parsing error or a permissions issue reading the file,
# we'll just skip netrc auth unless explicitly asked to raise errors.
if raise_errors:
raise
# App Engine hackiness.
except (ImportError, AttributeError):
pass
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does get_netrc_auth() do?
get_netrc_auth() is a function in the requests codebase, defined in src/requests/utils.py.
Where is get_netrc_auth() defined?
get_netrc_auth() is defined in src/requests/utils.py at line 205.
What does get_netrc_auth() call?
get_netrc_auth() calls 1 function(s): get.
What calls get_netrc_auth()?
get_netrc_auth() is called by 2 function(s): prepare_request, rebuild_auth.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free