get_netrc_auth: handle os.path.expanduser failure

os.path.expanduser can raise a KeyError when $HOME is not set and the
POSIX getpwuid() call fails, which can happen when running under a UID
which is not in /etc/passwd or when the password file cannot be read.

The upstream bug report http://bugs.python.org/issue20164 is unlikely to
be backported to Python 2.x even if fixed so this change handles
KeyError by skipping netrc authentication.

Closes #1846
get_netrc_auth: code cleanup

* Stop iterating as soon as we find a netrc file
* More obvious return None
Merge pull request #1846 from acdha/paranoid-get_netrc_auth

get_netrc_auth should handle os.path.expanduser failing