jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] site_detect: Fail with more specific error ......................................................................
[IMPROV] site_detect: Fail with more specific error
When the API from a private wiki isn't exposed it may be able to determine the API path but it may not be able to determine the articlepath. This is guessing the article path from the original URL (if it wasn't the API URL) and also sets the language to the family name as a fallback.
Bug: T112575 Change-Id: Ib7bc898ea179c5806a40260dbb69abf2084ed973 --- M generate_family_file.py M pywikibot/site_detect.py 2 files changed, 21 insertions(+), 1 deletion(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/generate_family_file.py b/generate_family_file.py index b4675f8..520434b 100755 --- a/generate_family_file.py +++ b/generate_family_file.py @@ -84,6 +84,8 @@ print(e, "; continuing...")
if len([lang for lang in self.langs if lang['url'] == w.iwpath]) == 0: + if w.private_wiki: + w.lang = self.name self.langs.append({u'language': w.lang, u'local': u'', u'prefix': w.lang, diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index 16aace9..8b7d888 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -88,6 +88,18 @@ if not self.api: raise RuntimeError('Unsupported url: {0}'.format(self.fromurl))
+ if not self.articlepath: + if self.private_wiki: + if self.api != self.fromurl and self.private_wiki: + self.articlepath = self.fromurl.rsplit('/', 1)[0] + '/$1' + else: + raise RuntimeError( + 'Unable to determine articlepath because the wiki is ' + 'private. Use the Main Page URL instead of the API.') + else: + raise RuntimeError('Unable to determine articlepath: ' + '{0}'.format(self.fromurl)) + if (not self.version or self.version < MediaWikiVersion('1.14')): raise RuntimeError('Unsupported version: {0}'.format(self.version)) @@ -145,7 +157,13 @@ def _parse_post_117(self): """Parse 1.17+ siteinfo data.""" response = fetch(self.api + '?action=query&meta=siteinfo&format=json') - info = json.loads(response.content)['query']['general'] + info = json.loads(response.content) + self.private_wiki = ('error' in info and + info['error']['code'] == 'readapidenied') + if self.private_wiki: + return + + info = info['query']['general'] self.version = MediaWikiVersion.from_generator(info['generator']) if self.version < MediaWikiVersion('1.17'): return
pywikibot-commits@lists.wikimedia.org