Skip to content
Myr

Respect the NETRC environment variable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mathieu Pichette · committed by Mathieu Pichette · parent 1431502 · Browse files · 2 files+10 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−3 removed

  • other:+10 added−3 removed

2 files+10 added−3 removed

modified:docs/user/quickstart.rst+2 added-1 removed
211 unmodified lines
212Note: Custom headers are given less precedence than more specific sources of information. For instance:213214* Authorization headers set with `headers=` will be overridden if credentials215 are specified in ``.netrc``, which in turn will be overridden by the ``auth=``216 parameter.216 parameter. Requests will search for the netrc file at `~/.netrc`, `~/_netrc`,217 or at the path specified by the `NETRC` environment variable.218* Authorization headers will be removed if you get redirected off-host.219* Proxy-Authorization headers will be overridden by proxy credentials provided in the URL.220* Content-Length headers will be overridden when we can determine the length of the content.221
343 unmodified lines
modified:requests/utils.py+8 added-2 removed
167 unmodified lines
168169def get_netrc_auth(url, raise_errors=False):170 """Returns the Requests tuple auth for a given url from netrc."""171172 netrc_file = os.environ.get('NETRC')173 if netrc_file is not None:174 netrc_locations = (netrc_file,)175 else:176 netrc_locations = ('~/{}'.format(f) for f in NETRC_FILES)177178 try:179 from netrc import netrc, NetrcParseError180181 netrc_path = None182177 for f in NETRC_FILES:183 for f in netrc_locations:184 try:179 loc = os.path.expanduser('~/{}'.format(f))185 loc = os.path.expanduser(f)186 except KeyError:187 # os.path.expanduser can fail when $HOME is undefined and188 # getpwuid fails. See https://bugs.python.org/issue20164 &189 # https://github.com/psf/requests/issues/1846
799 unmodified lines