Skip to content
Myr

Allow get_netrc_auth to raise parse/permission errors to caller

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

If the netrc file exists but cannot be parsed or read, get_netrc_auth silently fails. Add a new argument `ignore_errors` which when set to False will cause any parse/permission errors to be raised to the caller. The default value is True, which means the default behavior is unchanged. Fixes #2654

authored by David Pursehouse · committed by David Pursehouse · parent f5dacf8 · Browse files · 1 file+3 added−2 removed
This commit

State

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

Trailers

  • Change-Id: I7436aaaf593178673ab84fd9e7ab4bcb0e3fe75e

Diff stats

1 file+3 added−2 removed

  • other:+3 added−2 removed

1 file+3 added−2 removed

modified:requests/utils.py+3 added-2 removed
65 unmodified lines
66 # e.g. BytesIO, cStringIO.StringIO67 return len(o.getvalue())686970def get_netrc_auth(url):70def get_netrc_auth(url, ignore_errors=True):71 """Returns the Requests tuple auth for a given url from netrc."""7273 try:74 from netrc import netrc, NetrcParseError
30 unmodified lines
105 return (_netrc[login_i], _netrc[2])106 except (NetrcParseError, IOError):107 # If there was a parsing error or a permissions issue reading the file,108 # we'll just skip netrc auth109 pass109 if not ignore_errors:110 raise111112 # AppEngine hackiness.113 except (ImportError, AttributeError):114 pass
594 unmodified lines