Page MenuHomePhabricator

NoUsername error
Closed, InvalidPublic

Description

While trying to login to Pywikibot using the command python3 pwb.py login, I am getting the following error

Skipped '/home/user/pywikibot/core_stable/user-config.py': writeable by others.
family and mylang are not set.
Defaulting to family='wikipedia' and mylang='test'.
WARNING: No user is logged in on site wikipedia:test
Traceback (most recent call last):
  File "/home/user/pywikibot/core_stable/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 "pwb.py", line 363, in <module>
   if not main():
  File "pwb.py", line 355, in main
   run_python_file(filename,
  File "pwb.py", line 74, in run_python_file
   exec(compile(source, filename, 'exec', dont_inherit=True),
  File "./scripts/login.py", line 192, in <module>
   main()
  File "./scripts/login.py", line 174, in main
   site.login(autocreate=autocreate)
  File "/home/user/pywikibot/core_stable/pywikibot/tools/__init__.py", line 1481, in wrapper
   return obj(*__args, **__kw)
  File "/home/user/pywikibot/core_stable/pywikibot/site/__init__.py", line 333, in login
   login_manager = api.LoginManager(site=self, user=self.username())
  File "/home/user/pywikibot/core_stable/pywikibot/tools/__init__.py", line 1481, in wrapper
   return obj(*__args, **__kw)
  File "/home/user/pywikibot/core_stable/pywikibot/login.py", line 117, in __init__
   raise NoUsername(
pywikibot.exceptions.NoUsername: ERROR: username for wikipedia:test is undefined.
If you have a username for that site, please add a line to user-config.py as follows:
usernames['wikipedia']['test'] = 'myUsername'
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.NoUsername'>

Since the wiki is a third party wiki, I have actually created password.py file, added the family file and also created the user-config.py file. But still the error is showing

Task copied from https://www.mediawiki.org/wiki/Topic:W0k4pyrrae4jxx6v

Event Timeline

Could you please show your user-config.py and the family file here. Seems the username is not found.

Contents of user-config.py

mylang='ml'
family='school'
usernames['school']['*']=u'Adithyakbot'
console_encoding='utf-8'
password_file='password.py'

Contents of school_family.py

# -*- coding: utf-8 -*-
"""
This family file was auto-generated by generate_family_file.py script.

Configuration parameters:
  url = https://schoolwiki.in
  name = school

Please do not commit this to the Git repository!
"""
from pywikibot import family


class Family(family.Family):  # noqa: D101

    name = 'school'
    langs = {
        'ml': 'schoolwiki.in',
    }

    def scriptpath(self, code):
        return {
            'ml': '',
        }[code]

    def protocol(self, code):
        return {
            'ml': 'https',
        }[code]
    def ignore_certificate_error(self, code):
        return True
JJMC89 added a subscriber: JJMC89.

user-config.py is writeable by others, so it is not being read.

Thanks for the solution. I actually copied the same from Windows.