Revision: 6902 Author: russblau Date: 2009-05-17 21:17:10 +0000 (Sun, 17 May 2009)
Log Message: ----------- Fixing login problems; the root issue is that when you use secure.wikimedia.org to login, the API sets cookies that can only be used on secure.wikimedia.org, so we now have to use SSL for all API queries.
Modified Paths: -------------- branches/rewrite/pywikibot/config2.py branches/rewrite/pywikibot/data/api.py branches/rewrite/pywikibot/login.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/config2.py =================================================================== --- branches/rewrite/pywikibot/config2.py 2009-05-17 16:44:38 UTC (rev 6901) +++ branches/rewrite/pywikibot/config2.py 2009-05-17 21:17:10 UTC (rev 6902) @@ -71,7 +71,7 @@ # Security Connection for Wikimedia Projects # use_SSL_onlogin = True # if available, use SSL when logging in -use_SSL_always = False # if available, use SSL for all API queries +use_SSL_always = True # if available, use SSL for all API queries
# Available security projects available_ssl_project = [
Modified: branches/rewrite/pywikibot/data/api.py =================================================================== --- branches/rewrite/pywikibot/data/api.py 2009-05-17 16:44:38 UTC (rev 6901) +++ branches/rewrite/pywikibot/data/api.py 2009-05-17 21:17:10 UTC (rev 6902) @@ -185,6 +185,8 @@ from pywikibot.comms import http
params = self.http_params() + if self.site._loginstatus == -3: + self.site.login(False) while True: action = self.params.get("action", "") write = action in ( @@ -248,14 +250,14 @@ status = self.site._loginstatus # save previous login status if ( ("error" in result and result["error"]["code"].endswith("limit")) - or (status != -1 + or (status >= 0 and self.site._userinfo['name'] != self.site._username[status])): # user is no longer logged in (session expired?) # reset userinfo, then make user log in again del self.site._userinfo self.site._loginstatus = -1 - if status == -1: + if status < 0: status = 0 # default to non-sysop login self.site.login(status) # retry the previous query @@ -672,6 +674,7 @@ lgname=self.username, lgpassword=self.password ) + self.site._loginstatus = -2 login_result = login_request.submit() if u"login" not in login_result: raise RuntimeError("API login response does not have 'login' key.") @@ -692,6 +695,7 @@ raise APIError(code=login_result["login"]["result"], info="")
def storecookiedata(self, data): + # ignore data; cookies are set by threadedhttp module pywikibot.cookie_jar.save()
Modified: branches/rewrite/pywikibot/login.py =================================================================== --- branches/rewrite/pywikibot/login.py 2009-05-17 16:44:38 UTC (rev 6901) +++ branches/rewrite/pywikibot/login.py 2009-05-17 21:17:10 UTC (rev 6902) @@ -142,9 +142,9 @@ The argument data is the raw data, as returned by getCookie().
""" - filename = config.datafilepath('%s-%s-%s-login.data' - % (self.site.family.name, self.site.code, - self.username)) + # THIS IS OVERRIDDEN IN data/api.py + filename = config.datafilepath('pywikibot.lwp') + logger.debug(u"Storing cookies to %s" % filename) f = open(filename, 'w') f.write(data) f.close()
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2009-05-17 16:44:38 UTC (rev 6901) +++ branches/rewrite/pywikibot/site.py 2009-05-17 21:17:10 UTC (rev 6902) @@ -123,10 +123,6 @@ if not hasattr(self, "_throttle"): self._throttle = Throttle(self, multiplydelay=True, verbosedelay=True) - try: - self.login(False) - except pywikibot.NoUsername: - pass return self._throttle
@property @@ -617,11 +613,12 @@ self.sitelock = threading.Lock() self._msgcache = {} self.nocapitalize = self.code in self.family.nocapitalize - # _loginstatus: -2 means login not yet attempted, + # _loginstatus: -3 means login not yet attempted, + # -2 means login attempt in progress, # -1 means not logged in (anon user), # 0 means logged in as user, # 1 means logged in as sysop - self._loginstatus = -2 + self._loginstatus = -3 return
# ANYTHING BELOW THIS POINT IS NOT YET IMPLEMENTED IN __init__() @@ -656,19 +653,16 @@ # check whether a login cookie already exists for this user if not hasattr(self, "_userinfo"): self.getuserinfo() -## if self._userinfo['name'] == self._username[sysop]: -## self._loginstatus = sysop -## return if self.logged_in(sysop): return loginMan = api.LoginManager(site=self, sysop=sysop, user=self._username[sysop]) if loginMan.login(retry = True): self._username[sysop] = loginMan.username - self._loginstatus = sysop if hasattr(self, "_userinfo"): del self._userinfo self.getuserinfo() + self._loginstatus = sysop else: self._loginstatus = -1 # failure if not hasattr(self, "_siteinfo"):