Page MenuHomePhabricator

checkimages.py gives string formatting error
Closed, InvalidPublic

Description

checkimages.py gives error:
File "./scripts/checkimages.py", line 1593, in checkStep

notification = nn % self.imageName

TypeError: not all arguments converted during string formatting
<type 'exceptions.TypeError'>

Event Timeline

Hidayatsrf renamed this task from checkimages.py to checkimages.py gives string formatting error.Feb 12 2017, 2:57 AM

What is your output of python pwb.py version?

zhuyifei1999 raised the priority of this task from High to Needs Triage.Feb 12 2017, 10:17 AM

Latest version from github, I am using python version 3.6.0, maybe the %s
no longer used?

Line 1593 of latest version isn't notification = nn % self.imageName. In any case, the full traceback and the command that ran the script would help too.

Xqt subscribed.

Looks like a wrong/missing L10N string. Could you please give me the complete command line and the site you are working on?

I am just localize it on idwiki, run using -commons -duplicates
-duplicatesreport. But it worked when I try change folowing line:
pywikibot.output(u"%s has only text and not the specific license..."

                 % self.imageName)
if hiddenTemplateFound and HiddenTN:
    notification = HiddenTN % self.imageName
elif nn:
    notification = nn % self.imageName

To:
pywikibot.output(u"{0} has only text and not the specific license..."

                 % self.imageName)
if hiddenTemplateFound and HiddenTN:
    notification = HiddenTN % self.imageName
elif nn:
    notification = nn .import (self.imageName)

Uh, sorry, '.format' not '.import'

On master, nn is: nn = i18n.translate(self.site, nothing_notification). Testing this:

$ python pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> import checkimages
>>> site = pywikibot.Site('id', 'wikipedia')
>>> from pywikibot import i18n
>>> i18n.translate(site, checkimages.nothing_notification)
>>> 

Expected output of i18n on master: None, and the exception-raising line will not be run. I believe something is wrong with your localization of nothing_notification. If that's the case, I'm inclined to close this as INVALID as this is an error from the user's own modification.

The result is:
$ python pwb.py shell
Welcome to the Pywikibot interactive shell!

import checkimages
site = pywikibot.Site('id', 'wikipedia')
i18n.translate(site, checkimages.nothing_notification)

Traceback (most recent call last):

File "<console>", line 1, in <module>

NameError: name 'i18n' is not defined

I meant you missed that line from my original test. The original test was:

$ python pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> import checkimages
>>> site = pywikibot.Site('id', 'wikipedia')
>>> from pywikibot import i18n
>>> i18n.translate(site, checkimages.nothing_notification)
>>> 

Just before i18n.translate(site, checkimages.nothing_notification) there is from pywikibot import i18n which you missed, hence the NameError: name 'i18n' is not defined.

nothing_notification dict is not localized for id-wiki. I guess you have localized yourself that dict but the id-wiki string value has a missing replace parameter "%s" e.g.
'foo' % 'bar' leads to that error mentioned above
'foo'.format('bar') is safe and just returns 'foo'

I think the best to solve this is to localize the script in an appropriate way.