I'm creating a semi-automated tool in Python, using pywikibot, to import data from TOP500 database into Wikidata, following this and this tutorial. (Is my first time programming in Python).
It ran fine, until the script attempts to commit a numeric value within a unit (for example, Pleiades (Q2442043
) → power consumed (P2791) → 4407.00 kW). The script parses the numeric value within the unit, then, the unit is converted to the given statement (kW → kilowatt (Q3320608
)). However, the script throws error (it is a warning due I'm handling errors using try-except) when passing the unit as URL (entity helper string) as well as statement (QXXXXX):
WARNING: API error modification-failed: Illegal value: https://wikidata.org/wiki/Q79738
Traceback (most recent call last):
File "/mnt/c/Users/Davod/Documents/git/wikidata_top500/core/pywikibot/page.py", line 112, in handle
func(self, *args, **kwargs)
File "/mnt/c/Users/Davod/Documents/git/wikidata_top500/core/pywikibot/page.py", line 4325, in addClaim
self.repo.addClaim(self, claim, bot=bot, **kwargs)
File "/mnt/c/Users/Davod/Documents/git/wikidata_top500/core/pywikibot/site.py", line 1326, in callee
return fn(self, *args, **kwargs)
File "/mnt/c/Users/Davod/Documents/git/wikidata_top500/core/pywikibot/site.py", line 7946, in addClaim
data = req.submit()
File "/mnt/c/Users/Davod/Documents/git/wikidata_top500/core/pywikibot/data/api.py", line 2080, in submit
raise APIError(**result['error'])
pywikibot.data.api.APIError: modification-failed: Illegal value: https://wikidata.org/wiki/Q79738 [messages:[{'name': 'wikibase-validator-not-allowed', 'parameters': ['https://wikidata.org/wiki/Q79738'], 'html': {'*': 'Valor ilegal: <a class="external free" href="https://wikidata.org/wiki/Q79738">https://wikidata.org/wiki/Q79738</a>'}}]; help:See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.]
I uploaded my project to GitHub. Relevant source code is found at the addClaim()
function, line 109.