Page MenuHomePhabricator

archivebot.py failing with uncaught exception <class 'ImportError'>
Closed, InvalidPublicBUG REPORT

Description

My archiving cronjob on toolforge has stopped working from 30 April (last successful archiving run 29 April)

Error message is

tools.wikisource-bot@tools-sgebastion-07:~$ python3  /shared/pywikipedia/core/scripts/archivebot.py User:Wikisource-bot/config

Traceback (most recent call last):
  File "/shared/pywikipedia/core/scripts/archivebot.py", line 112, in <module>
    from pywikibot.exceptions import Error, NoPageError
ImportError: cannot import name 'NoPageError'
CRITICAL: Exiting due to uncaught exception <class 'ImportError'>

All was working fine to that date, and I have not made any changes to any settings/commands. [It is shared account so cannot say authoritatively for others, though seems less likely]

Event Timeline

Xqt changed the subtype of this task from "Task" to "Bug Report".May 13 2021, 6:53 AM
Xqt added a subscriber: atagar.

The central version on toolforge, I just use whatever is there

tools.wikisource-bot@tools-sgebastion-07:~$ python3 scripts/version.py

Pywikibot: [https] r-pywikibot-core.git (ef4ee7f, g1, 2021/05/10, 14:17:24, stable)
Release version: 6.1.0
requests version: 2.21.0
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.5.3 (default, Apr  5 2021, 09:00:41)
[GCC 6.3.0 20170516]

Looks like Pywikibot is 6.1.0 but archivebot is 6.2.0.dev0. Are scripts provided in a different way?

I looked into this after @Billinghurst asked on IRC, it basically was what @Xqt identified, a different version of core and scripts.

If you do a plain import pywikibot, it imports the stable version from /data/project/shared/pywikibot/stable/pywikibot/__init__.py.

But /shared/pywikipedia/core/ points to /data/project/pywikibot/public_html/core which is *master*, not stable.

So the correct invocation should be: $ python3 /shared/pywikibot/core_stable/scripts/archivebot.py

Another thing I noticed is that /shared/pywikipedia and /shared/pywikibot are different:

$ ls -l /shared/pywikipedia
total 8
lrwxrwxrwx 1 valhallasw      project-tools     42 Dec  4  2013 compat -> /data/project/pywikibot/public_html/compat
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot    6 Mar 23  2019 compat_old -> compat
lrwxrwxrwx 1 valhallasw      project-tools     40 Dec  4  2013 core -> /data/project/pywikibot/public_html/core
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot   47 Mar 23  2019 core_old -> /data/project/pywikibot/public_html/core_stable
drwxrwsr-x 3 tools.russbot   project-tools   4096 Mar 23  2019 core_old_moved
-rw-rw-r-- 1 tools.pywikibot tools.pywikibot   68 Apr 23  2018 README.md
lrwxrwxrwx 1 tools.russbot   project-tools      4 Jul 29  2013 rewrite -> core
lrwxrwxrwx 1 tools.russbot   project-tools      6 Jul 29  2013 trunk -> compat
$ ls -l /shared/pywikibot
total 4
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot  40 Apr 23  2018 core -> /data/project/pywikibot/public_html/core
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot  48 Feb 28  2020 core_python2 -> /data/project/pywikibot/public_html/core_python2
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot  47 Mar 23  2019 core_stable -> /data/project/pywikibot/public_html/core_stable
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot  12 Mar 24  2020 python2 -> core_python2
-rw-rw-r-- 1 tools.pywikibot tools.pywikibot 393 Feb 28  2020 README.md
lrwxrwxrwx 1 tools.pywikibot tools.pywikibot  11 Mar 24  2020 stable -> core_stable

It would be nice if we could just symlink /shared/pywikipedia -> /shared/pywikibot, I don't know why we didn't do that in the past.

I looked into this after @Billinghurst asked on IRC, it basically was what @Xqt identified, a different version of core and scripts.

If you do a plain import pywikibot, it imports the stable version from /data/project/shared/pywikibot/stable/pywikibot/__init__.py.

But /shared/pywikipedia/core/ points to /data/project/pywikibot/public_html/core which is *master*, not stable.

So the correct invocation should be: $ python3 /shared/pywikibot/core_stable/scripts/archivebot.py

Looks there is a mess with versions and its usage is not documented well. I am not familar with toolforge but I think the usual way to use Pywikibot is to use ist stable branch version which is deployed monthly after tests passes. The master branch may be used by their own risk but is also very welcomed for beta testers and I know that a lot of bugs might be undetected unless it is used by a production system. But anyway a cross usage should be avoided anyhow. A newer script can probably fail with an older Pywikibot release like in this case. An older script works with a newer Pywikibot release but can throw a DeprecationWarning or show a FutureWarning. If a FutureWarning is shown the deprecated part might be removed with the overnext Python release.

What I have found is that I had a symlink to one path .../core/ and Legotkm pointed me to this other path. I see that the documentation at wikitech for pywikibot was changed to a .../stable/ path and it was not something noticed. I have changed my symlink. So it is an artefact of a change to how wikitech deployed pywikibot. I am guessing that it came in the change to python3.

I will note that there was no version data in archiverbot.py for me to see or have any easy point of comparison.

I will note that there was no version data in archiverbot.py for me to see or have any easy point of comparison.

That looks like a good idea.

Unfortunately toolforge user seems not to use the pwb wrapper. This is ok but is giving up its advantages:

  • dependency check
  • config check
  • provide global options for every scripts even it is not calling handle_args()
  • use of redirected script folders
  • find similar script names due to spelling mistakes

@bd808 Can I bring you in here Brian? Not only out of my grade, put different planet

Change 690472 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] Show a warning if pywikibot.__version__ is behind scrips.__version__

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

Change 690565 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] Enable generate_family_file to force verify

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

Change 690565 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] Enable generate_family_file to force verify

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

Change 690472 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] Show a warning if pywikibot.__version__ is behind scripts.__version__

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