diff -r 5673cf852daa Lib/netrc.py --- a/Lib/netrc.py Sat Oct 01 01:06:51 2016 -0500 +++ b/Lib/netrc.py Sun Oct 02 16:47:15 2016 +0200 @@ -23,10 +23,7 @@ def __init__(self, file=None): default_netrc = file is None if file is None: - try: - file = os.path.join(os.environ['HOME'], ".netrc") - except KeyError: - raise OSError("Could not find .netrc: $HOME is not set") + file = os.path.expanduser("~/.netrc") self.hosts = {} self.macros = {} with open(file) as fp: diff -r 5673cf852daa Lib/test/test_netrc.py --- a/Lib/test/test_netrc.py Sat Oct 01 01:06:51 2016 -0500 +++ b/Lib/test/test_netrc.py Sun Oct 02 16:47:15 2016 +0200 @@ -123,6 +123,11 @@ os.chmod(fn, 0o622) self.assertRaises(netrc.NetrcParseError, netrc.netrc) + def test_no_home_in_env(self): + with support.EnvironmentVarGuard() as environ: + environ.unset('HOME') + nrc = netrc.netrc() + def test_main(): support.run_unittest(NetrcTestCase)