jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/842505 )
Change subject: [IMPR] Enable 2FA login with Pywikibot ......................................................................
[IMPR] Enable 2FA login with Pywikibot
Bug: T186274 Change-Id: I1113734c0456ed0b8d734c07514c5ca2d47a4fa4 --- M pywikibot/data/api/_login.py 1 file changed, 17 insertions(+), 1 deletion(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api/_login.py b/pywikibot/data/api/_login.py index 11de1ae..f88a371 100644 --- a/pywikibot/data/api/_login.py +++ b/pywikibot/data/api/_login.py @@ -18,7 +18,11 @@
class LoginManager(login.LoginManager):
- """Supply login_to_site method to use API interface.""" + """Supply login_to_site method to use API interface. + + .. versionchanged:: 8.0 + 2FA login was enabled. + """
# API login parameters mapping mapping = { @@ -69,6 +73,9 @@
Note, this doesn't do anything with cookies. The http module takes care of all the cookie stuff. Throws exception on failure. + + .. versionchanged:: 8.0 + 2FA login was enabled. """ self.below_mw_1_27 = False if hasattr(self, '_waituntil') \ @@ -131,6 +138,15 @@ self.keyword('token')] = self.get_login_token() continue
+ if status == 'UI': + oathtoken = pywikibot.input(response['message'], password=True) + login_request['OATHToken'] = oathtoken + login_request['logincontinue'] = True + del login_request['username'] + del login_request['password'] + del login_request['rememberMe'] + continue + # messagecode was introduced with 1.29.0-wmf.14 # but older wikis are still supported login_throttled = response.get('messagecode') == 'login-throttled'