Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 782d940

Browse files
Guard against error if .netrc is missing.
1 parent 89350a4 commit 782d940

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Lib/nntplib.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,16 @@ def __init__(self, host, port=NNTP_PORT, user=None, password=None,
135135
raise
136136
# If no login/password was specified, try to get them from ~/.netrc
137137
# Presume that if .netc has an entry, NNRP authentication is required.
138-
if not user:
139-
import netrc
140-
credentials = netrc.netrc()
141-
auth = credentials.authenticators(host)
142-
if auth:
143-
user = auth[0]
144-
password = auth[2]
138+
try:
139+
if not user:
140+
import netrc
141+
credentials = netrc.netrc()
142+
auth = credentials.authenticators(host)
143+
if auth:
144+
user = auth[0]
145+
password = auth[2]
146+
except IOError:
147+
pass
145148
# Perform NNRP authentication if needed.
146149
if user:
147150
resp = self.shortcmd('authinfo user '+user)

0 commit comments

Comments
 (0)