I made a very simple script which simply prints the URL of a file. It throws a typeerror when the PageGenerator is being created.
#!/usr/bin/python # -*- 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()) print(url) 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: genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator(gen=generator) if not generator: pywikibot.bot.suggest_help(missing_generator=True) else: pregenerator = pagegenerators.PreloadingGenerator(generator) site.login() for page in pregenerator: if page.exists() and not page.isRedirectPage(): download(page) pywikibot.output("") if __name__ == "__main__": main()
This gives a TypeError when I try to use the RandomPageGenerator
$ python ../pywikibot-core/pwb.py download.py -namespaces:File -random:3 Traceback (most recent call last): File "../pywikibot-core/pwb.py", line 256, in <module> if not main(): File "../pywikibot-core/pwb.py", line 250, in main run_python_file(filename, [filename] + args, argvu, file_package) File "../pywikibot-core/pwb.py", line 121, in run_python_file main_mod.__dict__) File "download.py", line 37, in <module> main() File "download.py", line 23, in main genFactory.handleArg(arg) File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/pagegenerators.py", line 688, in handleArg namespace=namespaces) File "/home/ajk/Documents/wiki/pywikibot-core/pywikibot/tools/__init__.py", line 1414, in wrapper return obj(*__args, **__kw) TypeError: RandomPageGenerator() got an unexpected keyword argument 'namespace' <type 'exceptions.TypeError'> CRITICAL: Closing network session.