# HG changeset patch # User Hynek Schlawack # Date 1328785099 -3600 # Branch nntp-capas # Node ID fd5eaf3624c7bbdac88540c418856929a2224c73 # Parent 84f5a58a420091808d772995592d140bd606c152 Catch temporary errors and retry after login diff --git a/Lib/nntplib.py b/Lib/nntplib.py --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -339,13 +339,14 @@ # session if a TLS session is already active. self.tls_on = False + # Log in and encryption setup order is left to subclasses. + self.authenticated = False + # Inquire about capabilities (RFC 3977). self._caps = None - if capabilities: - self.getcapabilities() + self.getcapabilities_afterauth = False + self.getcapabilities() - # Log in and encryption setup order is left to subclasses. - self.authenticated = False def __enter__(self): return self @@ -379,6 +380,11 @@ self.nntp_implementation = None try: resp, caps = self.capabilities() + except NNTPTemporaryError: + if not self.authenticated: + # We probably need to login first + self.getcapabilities_afterauth = True + self._caps = {} except NNTPPermanentError: # Server doesn't support capabilities self._caps = {} @@ -956,6 +962,9 @@ resp = self._shortcmd('authinfo pass ' + password) if not resp.startswith('281'): raise NNTPPermanentError(resp) + # Try again to get caps if we've got a temporary error before login. + if self.getcapabilities_afterauth: + self._caps = self.getcapabilities() # Attempt to send mode reader if it was requested after login. if self.readermode_afterauth: self._setreadermode()