Originally reported at T261050#7670075
Having a login status other than AS_USER (LoginStatus(0)) when performing an action (e.g., editing) while logged in isn't correct.
$ python3 t.py -log -pt:0 site._loginstatus=LoginStatus(-3); site.logged_in()=False Logging in ... site._loginstatus=LoginStatus(-2); site.logged_in()=True Editing a page ... Page [[Pywikibot test]] saved site._loginstatus=LoginStatus(-2); site.logged_in()=True
t.py
import pywikibot pywikibot.handle_args() site = pywikibot.Site('test', 'wikipedia') pywikibot.output(f'{site._loginstatus=}; {site.logged_in()=}') pywikibot.output('Logging in ...') site.login() pywikibot.output(f'{site._loginstatus=}; {site.logged_in()=}') pywikibot.output('Editing a page ...') page = pywikibot.Page(site, 'Pywikibot test') page.text = f'Test {site.server_time()}' page.save(summary=page.text) pywikibot.output(f'{site._loginstatus=}; {site.logged_in()=}')
log
2022-02-01 20:56:23 bot.py, 468 in writelogheader: VERBOSE === Pywikibot framework v7.0.0.dev0 -- Logging header === 2022-02-01 20:56:23 bot.py, 472 in writelogheader: VERBOSE COMMAND: ['t.py', '-log', '-pt:0'] 2022-02-01 20:56:23 bot.py, 475 in writelogheader: VERBOSE DATE: 2022-02-02 04:56:23.065527 UTC 2022-02-01 20:56:23 bot.py, 479 in writelogheader: VERBOSE VERSION: [ssh] pywikibot-core (5fbfc49, g15894, 2022/02/01, 19:06:30, n/a) 2022-02-01 20:56:23 bot.py, 486 in writelogheader: VERBOSE SYSTEM: posix.uname_result(sysname='Linux', nodename='DESKTOP-OVSD685', release='5.10.16.3-microsoft-standard-WSL2', version='#1 SMP Fri Apr 2 22:23:49 UTC 2021', machine='x86_64') 2022-02-01 20:56:23 bot.py, 489 in writelogheader: VERBOSE CONFIG FILE DIR: /home/jjmc89/.pywikibot 2022-02-01 20:56:23 bot.py, 503 in writelogheader: VERBOSE PACKAGES: 2022-02-01 20:56:23 bot.py, 513 in writelogheader: VERBOSE mwparserfromhell (/home/jjmc89/.pyenv/versions/pwb-39/lib/python3.9/site-packages/mwparserfromhell) = 0.6.3 2022-02-01 20:56:23 bot.py, 513 in writelogheader: VERBOSE requests (/home/jjmc89/.pyenv/versions/pwb-39/lib/python3.9/site-packages/requests) = 2.27.1 [snip] 2022-02-01 20:56:23 t.py, 6 in <module>: INFO site._loginstatus=LoginStatus(-3); site.logged_in()=False 2022-02-01 20:56:23 t.py, 8 in <module>: INFO Logging in ... 2022-02-01 20:56:23 t.py, 10 in <module>: INFO site._loginstatus=LoginStatus(-2); site.logged_in()=True 2022-02-01 20:56:23 t.py, 12 in <module>: INFO Editing a page ... 2022-02-01 20:56:24 __init__.py, 1241 in _save: INFO Page [[Pywikibot test]] saved 2022-02-01 20:56:24 t.py, 16 in <module>: INFO site._loginstatus=LoginStatus(-2); site.logged_in()=True 2022-02-01 20:56:24 __init__.py, 1333 in _flush: VERBOSE Dropped throttle(s). 2022-02-01 20:56:24 http.py, 86 in flush: VERBOSE Closing network session. 2022-02-01 20:56:24 http.py, 92 in flush: VERBOSE Network session closed.