Steps to replicate the issue (include links if applicable):
- Configure a private mediawiki site on 1.35.10+
- Namely $wgGroupPermissions['*']['read'] = false; so that non-logged in users have zero access
- Confirm that https://private.wiki.com/w/api.php?action=query&meta=userinfo&uiprop=ratelimits fails when not logged in
- You should expect to receive the following error while not logged in if things have been configured correctly to create a private wiki:
{
"error": {
"code": "readapidenied",
"info": "You need read permission to use this module.",
"*": "See https://private.wiki.com/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
}
}- Configure pwb to access this private site per https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis
- Sample configs:
install -m 600 <(cat <<'EOF' mylang = 'en' user_families_paths = ['.'] family = 'private' usernames['private']['en'] = 'private' password_file = "user-password.py" logfilename = 'private.log' logfilecount = 0 logfilesize = 1048576 verbose_output = 5 log = ['*'] debug_log = ['*'] EOF ) user-config.py
install -m 600 <(cat <<'EOF'
('private', 'private', BotPassword('cli', 'Password'))
EOF
) user-password.py install -m 600 <(cat <<'EOF'
from pywikibot import family
class Family(family.Family):
name = 'private'
langs = {
'en': 'private.wiki.com',
}
def version(self, code):
return "1.35.10"
def scriptpath(self, code):
return '/w'
def protocol(self, code):
return 'HTTPS'
def isPublic(self):
return False
EOF
) private_family.py- Run pwb login
What happens?:
$ pwb login WARNING: API error readapidenied: You need read permission to use this module. WARNING: API error readapidenied: You need read permission to use this module. Logging in to private:en as private@cli Logged in on private:en as private.
due to this code:
https://github.com/wikimedia/pywikibot/blob/8dd5d1cfde3e95a2e492af0528a3d586848d76ca/pywikibot/site/_apisite.py#L664
Very similar to https://phabricator.wikimedia.org/T284577
What should have happened instead?:
Pywikibot should not attempt to perform any API calls until after a successful login on private wikis, i.e. there should not be any WARNING's with readapidenied before it has even attempted to login.
A new unit test should be created to validate this situation and ensure no API calls are made prior to login. Ideally Family.isPublic should be reinstated (I tried this and it didn't help likely because it is no longer used as noted by Chris Blom in the above issue). There should be a check in the request path that ensures NO API calls can occur prior to login for a private wiki.
From debug_log:
2024-05-26 18:15:05 _requests.py, 1116 in submit: VERBOSE API Error: query=
("{'action': ['query'], 'meta': ['userinfo'], 'uiprop': ['blockinfo', "
"'groups', 'hasmsg', 'ratelimits', 'rights'], 'formatversion': [2], 'maxlag': "
"['5'], 'format': ['json']}")
2024-05-26 18:15:05 _requests.py, 1118 in submit: VERBOSE response=
{'error': {'code': 'readapidenied', 'info': 'You need read permission to use this module.', 'docref': 'See https://private.wiki.com/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.'}}
2024-05-26 18:15:06 _requests.py, 1056 in submit: WARNING API error readapidenied: You need read permission to use this module.Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):
MediaWiki: 1.35.10
Pywikibot:
$ pwb version Pywikibot: pywikibot/__init__.py (, -1 (unknown), 2024/05/26, 16:24:47, UNKNOWN) Release version: 9.1.2 packaging version: 24.0 mwparserfromhell version: 0.6.6 wikitextparser version: n/a requests version: 2.32.2 cacerts: /home/private/.local/share/pipx/venvs/pywikibot/lib/python3.11/site-packages/certifi/cacert.pem certificate test: ok Python: 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801] PYWIKIBOT_DIR: Not set PYWIKIBOT_DIR_PWB: /home/private/.local/share/pipx/venvs/pywikibot/lib/python3.11/site-packages/pywikibot/scripts PYWIKIBOT_NO_USER_CONFIG: Not set
