jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645822 )
Change subject: [IMPR] Add additional info into log if 'messagecode' is missing
during login
......................................................................
[IMPR] Add additional info into log if 'messagecode' is missing during login
- log the api login_result dict
- raise CaptchaError with response dict
Bug: T261061
Bug: T269503
Change-Id: I27445916600bc6e49dfa92eb65e6f29df4ae1e26
---
M pywikibot/data/api.py
1 file changed, 17 insertions(+), 3 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 492bd61..6a56a8f 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -31,7 +31,7 @@
from pywikibot.backports import Tuple
from pywikibot.comms import http
from pywikibot.exceptions import (
- Server504Error, Server414Error, FatalServerError, NoUsername,
+ CaptchaError, Server504Error, Server414Error, FatalServerError, NoUsername,
Error, TimeoutError, MaxlagTimeoutError, InvalidTitle, UnsupportedPage
)
from pywikibot.family import SubdomainFamily
@@ -2957,9 +2957,23 @@
_invalidate_superior_cookies(self.site.family)
continue
+ # messagecode was introduced with 1.29.0-wmf.14
+ login_throttled = False
+ if self.site.mw_version >= '1.29.0-wmf.14':
+ try:
+ login_throttled = \
+ response['messagecode'] == 'login-throttled'
+ except KeyError:
+ pywikibot.log(
+ "Missing 'messagecode' key encountered\n"
+ 'Please file the following debug message to '
+ 'Phabricator task T261061:\n{}'
+ .format(login_result))
+ raise CaptchaError('Captcha encountered which cannot be '
+ 'handled:\n{}'.format(response))
+
if (status == 'Throttled' or status == self.keyword('fail')
- and (response['messagecode'] == 'login-throttled'
- or 'wait' in fail_reason)):
+ and (login_throttled or 'wait' in fail_reason)):
wait = response.get('wait')
if wait:
delta = datetime.timedelta(seconds=int(wait))
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/645822
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I27445916600bc6e49dfa92eb65e6f29df4ae1e26
Gerrit-Change-Number: 645822
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-MessageType: merged