File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed 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
213
213
214
214
* Authorization headers set with `headers= ` will be overridden if credentials
215
215
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.
217
218
* Authorization headers will be removed if you get redirected off-host.
218
219
* Proxy-Authorization headers will be overridden by proxy credentials provided in the URL.
219
220
* 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):
169
169
def get_netrc_auth (url , raise_errors = False ):
170
170
"""Returns the Requests tuple auth for a given url from netrc."""
171
171
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
+
172
178
try :
173
179
from netrc import netrc , NetrcParseError
174
180
175
181
netrc_path = None
176
182
177
- for f in NETRC_FILES :
183
+ for f in netrc_locations :
178
184
try :
179
- loc = os .path .expanduser ('~/{}' . format ( f ) )
185
+ loc = os .path .expanduser (f )
180
186
except KeyError :
181
187
# os.path.expanduser can fail when $HOME is undefined and
182
188
# getpwuid fails. See https://bugs.python.org/issue20164 &
You can’t perform that action at this time.
0 commit comments