Steps to reproduce:
site = pywikibot.Site() page = next(pagegenerators.AllpagesPageGenerator(namespace='File')) print(page.latest_file_info.mime
I tested it on our private mediawiki installation (1.39.6), but should be reproducible on any family/language. I'm using pywikibot 9.0.0 from PyPi.
Experienced output:
Traceback (most recent call last):
File "/home/test.py", line 223, in <module>
print(page.latest_file_info.mime)
AttributeError: 'FileInfo' object has no attribute 'mime'
CRITICAL: Exiting due to uncaught exception AttributeError: 'FileInfo' object has no attribute 'mime'Expected output:
Returns the MIME-Type
Analysis:
When loading file pages through a generator, attribute FilePage._file_revisions is already set and thus loadimageinfo does not get triggered for the FilePage. The attribute gets set since the PageGenerator object loads the imageinfo prop, but does not load all the attributes that loadimageinfo does. Thus, e.g. the MIME-type are not queried.
Suggested fix:
Ensure that whenever imageinfos are loaded, the same set of properties are loaded.
I. e. in __init__ of class PageGenerator (file data/api/_generators.py lines 707 & 708), change
append_params(parameters, 'iiprop', 'timestamp|user|comment|url|size|sha1')
to
append_params(parameters, 'iiprop', 'timestamp|user|comment|url|size|sha1|mime|mediatype|archivename|bitdepth')
If I apply this fix, my initial code snippet (and my application) work as expected.
Current workaround:
You can add the required fields manually to the loaded properties, this works for me:
site = pywikibot.Site()
gen = pagegenerators.AllpagesPageGenerator(namespace='File')
gen.request['iiprop'].append('mime')
page = next(gen)
print(page.latest_file_info.mimeCheers, thanks for the good work!