Page MenuHomePhabricator

User specified in -user is ignored when no username in config
Open, LowPublic

Description

$ python pwb.py login -user:Dvorapa -family:i18n
WARNING: /home/pavel/pywikibot/pywikibot/site.py:770: UserWarning: Global configuration variable "mylang" changed to "i18n" while instantiating site i18n:i18n
  % (self.__code, self), UserWarning)

WARNING: ./scripts/login.py:167: UserWarning: Site i18n:i18n instantiated using different code "cs"
  site = pywikibot.Site()

Traceback (most recent call last):
  File "/home/pavel/pywikibot/pywikibot/login.py", line 114, in __init__
    self.username = self.username or family_usernames['*']
KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 251, in <module>
    if not main():
  File "pwb.py", line 244, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 115, in run_python_file
    main_mod.__dict__)
  File "./scripts/login.py", line 196, in <module>
    main()
  File "./scripts/login.py", line 179, in main
    site.login(sysop, autocreate=autocreate)
  File "/home/pavel/pywikibot/pywikibot/site.py", line 2089, in login
    user=self._username[sysop])
  File "/home/pavel/pywikibot/pywikibot/tools/__init__.py", line 1446, in wrapper
    return obj(*__args, **__kw)
  File "/home/pavel/pywikibot/pywikibot/login.py", line 122, in __init__
    'wiki_code': self.site.code})
pywikibot.exceptions.NoUsername: ERROR: Username for i18n:i18n is undefined.
If you have an account for that site, please add a line to user-config.py:

usernames['i18n']['i18n'] = 'myUsername'
<class 'pywikibot.exceptions.NoUsername'>
CRITICAL: Closing network session.

Event Timeline

Dvorapa created this task.May 29 2018, 9:32 PM
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptMay 29 2018, 9:32 PM
Xqt triaged this task as Low priority.May 31 2018, 6:02 AM
Dalba added a subscriber: Dalba.EditedJun 10 2018, 12:26 PM

You are only defining a -family, but not a -lang, therefore pywikibot sets the provided -user for <-family>:<mylang>, where <mylang> is the default language defined in user-config.py. In this case, it's "cs", hence the warning UserWarning: Site i18n:i18n instantiated using different code "cs".

Calling python pwb.py login -user:Dvorapa -family:i18n -lang:i18n should work fine.

We can enforce the -user on all sites within the specified -family, but that would be a little bit of a breaking change for those who may rely on the current behavior, i.e. they may want the user to be set only to config.mylang, but prefer to use their user-config values for other langs.

I am currently in favor of a solution to make pywikibot raise an error instead of just showing a warning for unknown languages on a family. But that would also be a breaking change.

Dvorapa added a comment.EditedJun 10 2018, 1:28 PM

I see, I would more like some clear error message than this unclear warning message as Pywikibot does not login with corrected lang anyway. Or enforce the user set in -user.

Also if user-config.py is unreachable, but pwb.py login -user:abc -lang:de -family:fgh is run, it isn't working either.

Vvjjkkii renamed this task from User specified in -user is ignored when no username in config to 20baaaaaaa.Jul 1 2018, 1:07 AM
Vvjjkkii raised the priority of this task from Low to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from 20baaaaaaa to User specified in -user is ignored when no username in config.Jul 2 2018, 8:51 AM
CommunityTechBot lowered the priority of this task from High to Low.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.

Please have in mind the steps on this page and also on manual page (marked as outdated in its header) can be slightly outdated