Page MenuHomePhabricator

login.py should show a sensible error message when some tries to use it with OAuth
Closed, DuplicatePublic

Description

tl;dr: Pywikibot uses the usernames global for assertions, even when authentication happens via OAuth. Setting authenticate but not usernames will result in errors like NoUsername: Logged in on lang:family via OAuth as UserName, but expect as None. See Manual:Pywikibot/OAuth/Wikimedia as an example of how to set up the configuration correctly.


The current error message is: {P3657}
It's not impossible to figure out from that that you don't need to log in explicitly when using OAuth, but it's not exactly user-friendly either. It should just say something like "Skipping login, you are using OAuth so you are always logged in."

Two UX complications worth considering:

  • the user might have an OAuth token for the wiki which is invalid. Trying to use the login API would probably still fail in that case, but in uglier ways.
  • the user might have an OAuth token which is valid for the wiki on which they perform the login, but not for all wikis on which the session saved via login.py would be valid (if it's a CentralAuth session or something similar).

Event Timeline

Hm, I can't reproduce with current master, I just get Logged in on <wiki> as <user>.

@MarcoAurelio can you verify that you got the error with the latest version of Pywikibot?

The current error message is: {P3657}

Something wrong with this paste? https://phabricator.wikimedia.org/P3657 says access denied.

Hm, it looks like it's been created with custom access rules. @MarcoAurelio can you remove that? I don't think there is anything private in the paste.

Hm, it looks like it's been created with custom access rules. @MarcoAurelio can you remove that? I don't think there is anything private in the paste.

Access rules are now: registered users.

Hm, I can't reproduce with current master, I just get Logged in on <wiki> as <user>.

@MarcoAurelio can you verify that you got the error with the latest version of Pywikibot?

I'll update my local pywikibot and let you know. Before I went to bed yesterday the error message I received is what I pasted above :)

Same error:

F:\MWDEV\pywikibot-core>pwb.py login
Traceback (most recent call last):
  File "F:\MWDEV\pywikibot-core\pwb.py", line 257, in <module>
    if not main():
  File "F:\MWDEV\pywikibot-core\pwb.py", line 251, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "F:\MWDEV\pywikibot-core\pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File ".\scripts\login.py", line 193, in <module>
    main()
  File ".\scripts\login.py", line 176, in main
    site.login(sysop)
  File "F:\MWDEV\pywikibot-core\pywikibot\site.py", line 2052, in login
    'right': self._username[sysop]})
pywikibot.exceptions.NoUsername: Logged in on meta:meta via OAuth as MABot, but expect as None
<class 'pywikibot.exceptions.NoUsername'>
CRITICAL: Closing network session.

F:\MWDEV\pywikibot-core>

Executing a script without running pwb.py first also gives me error:

F:\MWDEV\pywikibot-core>pwb.py redirect br -delete -always -pt:1
Traceback (most recent call last):
  File "F:\MWDEV\pywikibot-core\pwb.py", line 257, in <module>
    if not main():
  File "F:\MWDEV\pywikibot-core\pwb.py", line 251, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "F:\MWDEV\pywikibot-core\pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File ".\scripts\redirect.py", line 804, in <module>
    main()
  File ".\scripts\redirect.py", line 797, in main
    pywikibot.Site().login()
  File "F:\MWDEV\pywikibot-core\pywikibot\site.py", line 2052, in login
    'right': self._username[sysop]})
pywikibot.exceptions.NoUsername: Logged in on meta:meta via OAuth as MABot, but expect as None
<class 'pywikibot.exceptions.NoUsername'>
CRITICAL: Closing network session.

F:\MWDEV\pywikibot-core>

Could you try to delete pywikibot.lwp and see if it still happens?

Apparently, not only the authenticate keys and tokens are needed in user-config when using OAuth. It looks like you still need the usernames['project']['lang']. I re-added those and my bot seems to work again.

I am not sure if this was the desired behaviour (that is, if you have the autenticate tokens still need the usernames in user-config).