Page MenuHomePhabricator

Logged in hiddenly
Closed, ResolvedPublicBUG REPORT

Description

I can edit Wikipedia, but cannot retrieve wachlist. The bot seems to be logged in and not logged in like Schrödinger's cat at the same time without pywikibot.lwp being present. I definitely deleted it, but bot still complains.
Command line:

`
c:\Pywikibot>python pwb.py -nolog _myscript.py
WARNING: API error notloggedin: Please log in to view or edit items on your watchlist.

c:\Pywikibot>python pwb.py -nolog login
Logged in on wikipedia:hu as BinBot.

c:\Pywikibot>rename pywikibot.lwp pywikibot-BinBot2.lwp

c:\Pywikibot>python pwb.py -nolog login
Logged in on wikipedia:hu as BinBot.

c:\Pywikibot>python pwb.py -nolog login -force
To force a re-login, please delete the revelant lines from 'c:\Pywikibot\pywikibot.lwp' (or the entire file) and try again.
Logged in on wikipedia:hu as BinBot.

c:\Pywikibot>del pywikibot.lwp
A következő fájl nem található: c:\Pywikibot\pywikibot.lwp (This means file not found.)

c:\Pywikibot>python pwb.py -nolog login -force
To force a re-login, please delete the revelant lines from 'c:\Pywikibot\pywikibot.lwp' (or the entire file) and try again.
Logged in on wikipedia:hu as BinBot.

c:\Pywikibot>dir c:\Pywikibot\pywikibot.lwp

A fájl nem található. (This means file not found.)

c:\Pywikibot>python pwb.py -nolog replace a b -page:user:BinBot/semmi -always -summary:"This sould not be saved, the bot is logged out"
Edit summary: This sould not be saved, the bot is logged out
Page [[Szerkesztő:BinBot/semmi]] saved

1 read operation
1 write operation
Execution time: 5 seconds
Read operation time: 5.0 seconds
Write operation time: 5.0 seconds
Script terminated successfully.
`

Steps to replicate the issue (include links if applicable): see above.

What happens?: Difflink: https://hu.wikipedia.org/w/index.php?title=Szerkeszt%C5%91:BinBot/semmi&curid=897695&diff=25853451&oldid=25838109

What should have happened instead?: Either be logged in or logged out. Definitely logged out after deleting pywikibot.lwp. -force should work in any circumstances, otherwise it is not a force.

Software version (skip for WMF-hosted wikis like Wikipedia):

c:\Pywikibot>python pwb.py -nolog version
Pywikibot: [https] r-pywikibot-core.git (b678f2e, g1, 2023/01/21, 12:29:25, OUTDATED)
Release version: 8.0.0
requests version: 2.25.1
  cacerts: C:\Python37\lib\site-packages\certifi\cacert.pem
    certificate test: ok
Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB: pywikibot\scripts
PYWIKIBOT_NO_USER_CONFIG: Not set
Traceback (most recent call last):
  File "pwb.py", line 39, in <module>
    sys.exit(main())
  File "pwb.py", line 35, in main
    runpy.run_path(str(path), run_name='__main__')
  File "C:\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "pywikibot\scripts\wrapper.py", line 516, in <module>
    main()
  File "pywikibot\scripts\wrapper.py", line 500, in main
    if not execute():
  File "pywikibot\scripts\wrapper.py", line 487, in execute
    run_python_file(filename, script_args, module)
  File "pywikibot\scripts\wrapper.py", line 148, in run_python_file
    main_mod.__dict__)
  File "scripts\version.py", line 85, in <module>
    main()
  File "scripts\version.py", line 75, in main
    pywikibot.output('Config base dir: ' + pywikibot.config2.base_dir)
AttributeError: module 'pywikibot' has no attribute 'config2'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>

Event Timeline

OK, even more strange. I deleted EVERY *.lwp (not just pywikibot.lwp that was written.) Now this happens:

c:\Pywikibot>python pwb.py -nolog login
WARNING: No user is logged in on site wikipedia:hu
Password for user BinBot on wikipedia:hu (no characters will be shown):
Logging in to wikipedia:hu as BinBot
Logged in on wikipedia:hu as BinBot.

c:\Pywikibot>python pwb.py -nolog _myscript.py
WARNING: API error notloggedin: Please log in to view or edit items on your watchlist.

Contents of the script:

import pywikibot
site = pywikibot.Site()
print(len(list(site.watched_pages())))

I'm not sure how the login script works, but you should be able to workaround the main issue by calling site.login() in your script:

import pywikibot
site = pywikibot.Site()
site.login()  # add this line, make sure username and password_file are defined in user-config.py
print(len(list(site.watched_pages())))

(this way, there should be no need to call pwb.py login before running the script)

site.login() # add this line, make sure username and password_file are defined in user-config.py

Great, this works, thank you! So the problem is not solved, but does not hurt me.

Xqt triaged this task as High priority.Apr 3 2023, 1:32 PM

Change 906547 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] No longer lazy load cookies

https://gerrit.wikimedia.org/r/906547

Change 906547 merged by Xqt:

[pywikibot/core@master] [bugfix] No longer lazy load cookies

https://gerrit.wikimedia.org/r/906547

Change 908207 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@stable] [bugfix] No longer lazy load cookies

https://gerrit.wikimedia.org/r/908207

Change 908207 merged by Xqt:

[pywikibot/core@stable] [bugfix] No longer lazy load cookies

https://gerrit.wikimedia.org/r/908207