jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/582610 )
Change subject: [bugfix] Fix logout on MW < 1.24 ......................................................................
[bugfix] Fix logout on MW < 1.24
- avoid Error as csrf token was introduced in MW 1.24 - don't test Fandom wikis as they don't support API action=logout
Bug: T214009 Change-Id: Ic2569e4ca02bce6fefee7b7b19a90769bdca7990 --- M pywikibot/site/__init__.py M tests/site_tests.py 2 files changed, 9 insertions(+), 3 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py index f9a4f64..59ae4ab 100644 --- a/pywikibot/site/__init__.py +++ b/pywikibot/site/__init__.py @@ -2120,8 +2120,13 @@ """ if self.is_oauth_token_available(): pywikibot.warning('Using OAuth suppresses logout function') - uirequest = self._simple_request(action='logout', - token=self.tokens['csrf']) + req_params = {'action': 'logout'} + # csrf token introduced in MW 1.24 + try: + req_params['token'] = self.tokens['csrf'] + except Error: + pass + uirequest = self._simple_request(**req_params) uirequest.submit() self._loginstatus = LoginStatus.NOT_LOGGED_IN
diff --git a/tests/site_tests.py b/tests/site_tests.py index 7a6de8d..e772cdc 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -3854,7 +3854,8 @@ loginstatus.AS_USER)) self.assertIn('_userinfo', site.__dict__.keys())
- else: + # Fandom family wikis don't support API action=logout + elif 'fandom.com' not in site.hostname(): site.logout() self.assertFalse(site.logged_in()) self.assertEqual(site._loginstatus, loginstatus.NOT_LOGGED_IN)
pywikibot-commits@lists.wikimedia.org