File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -213,7 +213,8 @@ Note: Custom headers are given less precedence than more specific sources of inf
213213
214214* Authorization headers set with `headers= ` will be overridden if credentials
215215 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.
217218* Authorization headers will be removed if you get redirected off-host.
218219* Proxy-Authorization headers will be overridden by proxy credentials provided in the URL.
219220* Content-Length headers will be overridden when we can determine the length of the content.
Original file line number Diff line number Diff line change @@ -169,14 +169,20 @@ def super_len(o):
169169def get_netrc_auth (url , raise_errors = False ):
170170 """Returns the Requests tuple auth for a given url from netrc."""
171171
172+ 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 )
177+
172178 try :
173179 from netrc import netrc , NetrcParseError
174180
175181 netrc_path = None
176182
177- for f in NETRC_FILES :
183+ for f in netrc_locations :
178184 try :
179- loc = os .path .expanduser ('~/{}' . format ( f ) )
185+ loc = os .path .expanduser (f )
180186 except KeyError :
181187 # os.path.expanduser can fail when $HOME is undefined and
182188 # getpwuid fails. See https://bugs.python.org/issue20164 &
You can’t perform that action at this time.
0 commit comments