Page MenuHomePhabricator

Pywikibot: -random gives TypeError
Closed, ResolvedPublic


I made a very simple script which simply prints the URL of a file. It throws a typeerror when the PageGenerator is being created.

# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals

import os

import pywikibot
from pywikibot import pagegenerators

def download(page):
    url = os.path.split(page.fileUrl())

def main(*args):
    generator = None
    local_args = pywikibot.handle_args(args)
    site = pywikibot.Site('commons', 'commons')
    genFactory = pagegenerators.GeneratorFactory(site)
    for arg in local_args:

    generator = genFactory.getCombinedGenerator(gen=generator)
    if not generator:
        pregenerator = pagegenerators.PreloadingGenerator(generator)
        for page in pregenerator:
            if page.exists() and not page.isRedirectPage():

if __name__ == "__main__":

This gives a TypeError when I try to use the RandomPageGenerator

$ python ../pywikibot-core/ -namespaces:File -random:3
Traceback (most recent call last):
  File "../pywikibot-core/", line 256, in <module>
    if not main():
  File "../pywikibot-core/", line 250, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "../pywikibot-core/", line 121, in run_python_file
  File "", line 37, in <module>
  File "", line 23, in main
  File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/", line 688, in handleArg
  File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/tools/", line 1414, in wrapper
    return obj(*__args, **__kw)
TypeError: RandomPageGenerator() got an unexpected keyword argument 'namespace'
<type 'exceptions.TypeError'>
CRITICAL: Closing network session.

Event Timeline

AbdealiJK created this task.May 9 2016, 5:45 AM
Restricted Application added subscribers: pywikibot-bugs-list, Zppix, Aklapper. · View Herald TranscriptMay 9 2016, 5:45 AM
AbdealiJK claimed this task.May 9 2016, 5:58 AM
Mpaa added a subscriber: Mpaa.May 9 2016, 8:15 PM
This comment was removed by Mpaa.

Change 287884 had a related patch set uploaded (by AbdealiJK):
pagegenerators: Fix namespaces kwarg in -random

Change 287884 merged by jenkins-bot:
pagegenerators: Fix regression bugs in -random

Mpaa closed this task as Resolved.May 10 2016, 9:01 PM