diff options
Diffstat (limited to 'Lib/netrc.py')
-rw-r--r-- | Lib/netrc.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/netrc.py b/Lib/netrc.py index f0ae48cfed..734d94c8a6 100644 --- a/Lib/netrc.py +++ b/Lib/netrc.py @@ -26,8 +26,12 @@ class netrc: file = os.path.join(os.path.expanduser("~"), ".netrc") self.hosts = {} self.macros = {} - with open(file) as fp: - self._parse(file, fp, default_netrc) + try: + with open(file, encoding="utf-8") as fp: + self._parse(file, fp, default_netrc) + except UnicodeDecodeError: + with open(file, encoding="locale") as fp: + self._parse(file, fp, default_netrc) def _parse(self, file, fp, default_netrc): lexer = shlex.shlex(fp) |