From: Kenneth Reitz Date: Sat, 31 Mar 2012 07:08:12 +0000 (-0400) Subject: app engine #498 X-Git-Tag: v0.12.0~69 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=171b370b0e3bbc0288fb0e4addcef16bf670e324;p=services%2Fpython-requests.git app engine #498 --- diff --git a/requests/utils.py b/requests/utils.py index b722d99..8028442 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -37,34 +37,40 @@ def dict_to_sequence(d): def get_netrc_auth(url): """Returns the Requests tuple auth for a given url from netrc.""" - locations = (os.path.expanduser('~/{0}'.format(f)) for f in NETRC_FILES) - netrc_path = None + try: + locations = (os.path.expanduser('~/{0}'.format(f)) for f in NETRC_FILES) + netrc_path = None - for loc in locations: - if os.path.exists(loc) and not netrc_path: - netrc_path = loc + for loc in locations: + if os.path.exists(loc) and not netrc_path: + netrc_path = loc - # Abort early if there isn't one. - if netrc_path is None: - return netrc_path + # Abort early if there isn't one. + if netrc_path is None: + return netrc_path - ri = urlparse(url) + ri = urlparse(url) - # Strip port numbers from netloc - host = ri.netloc.split(':')[0] + # Strip port numbers from netloc + host = ri.netloc.split(':')[0] - 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, IOError, AttributeError): - # If there was a parsing error or a permissions issue reading the file, - # we'll just skip netrc auth + 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, IOError): + # If there was a parsing error or a permissions issue reading the file, + # we'll just skip netrc auth + pass + + # AppEngine hackiness. + except AttributeError: pass + def dict_from_string(s): """Returns a MultiDict with Cookies."""