I'm trying to get pywikibot set up for the first time. It's on a Miraheze site and I'm getting this error when I try to log in:
-----------
WARNING: Non-JSON response received from server comprehensibleinputwiki:en for url
https://comprehensibleinput.miraheze.org/w/api.php
The server may be down.
Status code: 200
The text message is:
MediaWiki API help - Comprehensible Input Wiki
document.documentElement.className="client-js";RLCONF={"wgBreakFrames":true,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"7a406c0d0d1c2121406e444b","wgCSPNonce":false,"wgCanonicalNamespace":"Special","wgCanonicalSpecialPageName":"ApiHelp","wgNamespaceNumber":-1,"wgPageName":"Special:ApiHelp","wgTitle":"ApiHelp","wgCurRevisionId":0,"wgRevisionId":0,"wgArticleId":0,"wgIsArticle":false,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Special:ApiHelp","wgRelevantArticleId":0,"wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgNoticeProject":"all",
...
------------
So it seems that it can access the page, but is not parsing it correctly for some reason. Anyone know what the issue is?
I wrote a script which requires admin rights. Someone told he couldn't use
it because Pywikibot does not supoort 2FA login. Is that correct?
--
Bináris
I've been beating my head against the wall trying to figure out how to build a Mock of APISite. If I do the obvious:
site = mocker.MagicMock(spec=APISite)
I end up with:
> AttributeError: Mock object has no attribute 'encodings'
Yet, if I hand-build a Site object, sure enough it does:
>>> import pywikibot
>>> site = pywikibot.Site("en", "wikipedia")
>>> site.encodings()
('utf-8', 'iso-8859-1')
>>>
To make a long story short, eventually I found this bit of magic in _basesite.py:
> def __getattr__(self, attr):
> """Delegate undefined methods calls to the Family object."""
> if hasattr(self.__class__, attr):
> return getattr(self.__class__, attr)
> try:
> method = getattr(self.family, attr)
> if not callable(method):
> raise AttributeError
> f = functools.partial(method, self.code)
> if hasattr(method, '__doc__'):
> f.__doc__ = method.__doc__
> return f
> except AttributeError:
> raise AttributeError("{} instance has no attribute '{}'"
> .format(self.__class__.__name__, attr))
WTF? I mean, I see what it's doing, but why go to this level of obfuscation? It's basically reimplementing class inheritance manually (and in a way which is totally beyond the ability of Mock to understand).