Page MenuHomePhabricator

Failure to read user-config.py
Closed, ResolvedPublicBUG REPORT

Description

My scripts (sample: x) apparently stopped reading user-config.py in the last few days.

A print(pywikibot.Site()) tells me that I am operating on test.wikipedia.org, and a manual setting of language and family to pywikibot.Site('en', 'wiktionary') gives me the following error.

ERROR: username for wiktionary:en is undefined.
If you have a username for that site, please add a line to user-config.py as follows:

After some digging, changing line 993 of config2.py to if False: allowed my scripts to function normally.

pywikibot version: pywikibot-5.3.0, installed via pip.

Event Timeline

JJMC89 triaged this task as High priority.Dec 30 2020, 10:50 AM
JJMC89 changed the subtype of this task from "Task" to "Bug Report".
JJMC89 added subscribers: Xqt, JJMC89.

From {b804528}

@Suzukaze-c: Have found your ERROR but it remains after the changed you have given:

>>> import pywikibot
>>> s = pywikibot.Site()
>>> s.login()
>>> s
APISite("de", "wikipedia")
>>> s = pywikibot.Site('skr')
>>> s
APISite("skr", "wikipedia")
>>> s.login()
Traceback (most recent call last):
  File "C:\pwb\GIT\core\pywikibot\login.py", line 115, in __init__
    user = code_to_usr.get(site.code) or code_to_usr['*']
KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    s.login()
  File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 1480, in wrapper
    return obj(*__args, **__kw)
  File "C:\pwb\GIT\core\pywikibot\site\__init__.py", line 327, in login
    login_manager = api.LoginManager(site=self, user=self.username())
  File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 1480, in wrapper
    return obj(*__args, **__kw)
  File "C:\pwb\GIT\core\pywikibot\login.py", line 117, in __init__
    raise NoUsername(
pywikibot.exceptions.NoUsername: ERROR: username for wikipedia:skr is undefined.
If you have a username for that site, please add a line to user-config.py as follows:
usernames['wikipedia']['skr'] = 'myUsername'
>>>

This is the default behavior if no username is set for a site.

Could you please file the result of pwb version please.

Ok, I think I got it.

As a workaround you can assign your user to the site e.g.

site = pywikibot.Site('wiktionary:en', user='Yourusername')

Change 652550 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Re-enable reading user-config.py from site package

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

Change 652550 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Re-enable reading user-config.py from site package

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

JJMC89 removed a project: Patch-For-Review.