jenkins-bot has submitted this change and it was merged.
Change subject: Stop login retrying if username is invalid
......................................................................
Stop login retrying if username is invalid
After an unsuccessful login using a password from the password file,
when the API returns 'NotExists' or 'Invalid', repeating the login
process with a new password supplied from the terminal by the user
will not remedy the situation. Raise NoUsername exception instead,
as the problem is a config issue.
Bug: 73533
Change-Id: I4276c47be2e34fb6aba3490e2b029f9276b7d03a
---
M pywikibot/exceptions.py
M pywikibot/login.py
2 files changed, 32 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Nullzero: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index b5013df..e711f48 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -3,7 +3,7 @@
Exception classes used throughout the framework.
Error: Base class, all exceptions should the subclass of this class.
- - NoUsername: Username is not in user-config.py
+ - NoUsername: Username is not in user-config.py, or it is invalid.
- UserBlockedY: our username or IP has been blocked
- AutoblockUser: requested action on a virtual autoblock user not valid
- UserActionRefuse
diff --git a/pywikibot/login.py b/pywikibot/login.py
index ee05bd1..db7be8f 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -37,6 +37,22 @@
@deprecated_args(username="user", verbose=None)
def __init__(self, password=None, sysop=False, site=None, user=None):
+ """
+ Constructor.
+
+ All parameters default to defaults in user-config.
+
+ @param site: Site object to log into
+ @type site: BaseSite
+ @param user: username to use
+ @type user: basestring
+ @param password: password to use
+ @type password: basestring
+ @param sysop: login as sysop account
+ @type sysop: bool
+
+ @raises NoUsername: No username is configured for the requested site.
+ """
if site is not None:
self.site = site
else:
@@ -169,6 +185,14 @@
password_f.close()
def login(self, retry=False):
+ """
+ Attempt to log into the server.
+
+ @param retry: infinitely retry if the API returns an unknown error
+ @type retry: bool
+
+ @raises NoUsername: Username is not recognised by the site.
+ """
if not self.password:
# As we don't want the password to appear on the screen, we set
# password = True
@@ -176,7 +200,6 @@
u'Password for user %(name)s on %(site)s (no characters will '
u'be shown):' % {'name': self.username, 'site':
self.site},
password=True)
-# self.password = self.password.encode(self.site.encoding())
pywikibot.output(u"Logging in to %(site)s as %(name)s"
% {'name': self.username, 'site': self.site})
@@ -184,6 +207,13 @@
cookiedata = self.getCookie()
except pywikibot.data.api.APIError as e:
pywikibot.error(u"Login failed (%s)." % e.code)
+ if e.code == 'NotExists':
+ raise NoUsername(u"Username '%s' does not exist on %s"
+ % (self.username, self.site))
+ elif e.code == 'Illegal':
+ raise NoUsername(u"Username '%s' is invalid on %s"
+ % (self.username, self.site))
+ # TODO: investigate other unhandled API codes (bug 73539)
if retry:
self.password = None
return self.login(retry=True)
--
To view, visit
https://gerrit.wikimedia.org/r/174035
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4276c47be2e34fb6aba3490e2b029f9276b7d03a
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>