Page MenuHomePhabricator

Show a proper message than raising AttributeError if not logged in
Closed, ResolvedPublic

Description

newitem.py needs to be logged in to run the script. Otherwise it raises a strange exception:
AttributeError: 'NoneType' object has no attribute 'startswith'
which is a proper message for that reason. Therefore force login if necessary tho show a proper message.

C:\pwb\GIT\core>py -3 pwb.py newitem -family:wikisource -lang:cs -simulate -start:Category:Du -pageage:0 -lastedit:0
WARNING: .\scripts\newitem.py:59: DeprecationWarning: pywikibot.site.APISite.getcurrenttime is deprecated for 5 years and 4 months; use pywikibot.site.APISite.server_time instead.
  self.pageAgeBefore = self.repo.getcurrenttime() - timedelta(

Sleeping for 5.0 seconds, 2020-04-30 14:27:31
Sleeping for 5.0 seconds, 2020-04-30 14:27:36
Sleeping for 5.0 seconds, 2020-04-30 14:27:41
Sleeping for 5.1 seconds, 2020-04-30 14:27:47
Sleeping for 6.3 seconds, 2020-04-30 14:27:52
Sleeping for 7.6 seconds, 2020-04-30 14:27:59
Sleeping for 8.9 seconds, 2020-04-30 14:28:07
Sleeping for 10.3 seconds, 2020-04-30 14:28:16
Sleeping for 11.6 seconds, 2020-04-30 14:28:27
Sleeping for 12.9 seconds, 2020-04-30 14:28:39
Sleeping for 14.2 seconds, 2020-04-30 14:28:52
Sleeping for 15.5 seconds, 2020-04-30 14:29:06
WARNING: .\scripts\newitem.py:61: DeprecationWarning: pywikibot.site.APISite.getcurrenttime is deprecated for 5 years and 4 months; use pywikibot.site.APISite.server_time instead.
  self.lastEditBefore = self.repo.getcurrenttime() - timedelta(

Page age is set to 0 days so only pages created
before 2020-04-30T12:29:16Z will be considered.
Last edit is set to 0 days so only pages last edited
before 2020-04-30T12:29:17Z will be considered.
Traceback (most recent call last):
  File "pwb.py", line 390, in <module>
    if not main():
  File "pwb.py", line 382, in main
    run_python_file(filename,
  File "pwb.py", line 100, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File ".\scripts\newitem.py", line 173, in <module>
    main()
  File ".\scripts\newitem.py", line 158, in main
    user = pywikibot.User(bot.site, bot.site.username())
  File "C:\pwb\GIT\core\pywikibot\tools\__init__.py", line 1797, in wrapper
    return obj(*__args, **__kw)
  File "C:\pwb\GIT\core\pywikibot\page\__init__.py", line 3195, in __init__
    if title.startswith('#'):
AttributeError: 'NoneType' object has no attribute 'startswith'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>

C:\pwb\GIT\core>

Details

Related Changes in Gerrit: