Page MenuHomeMiraheze

pywikibot doesn't detect "item_namespace" in nbdbwiki
Open, NormalPublic

Description

I believe this is an issue with the wiki's configuration, because the code I'm using is copy-pasted from a Wikidata tutorial (with a different user-config and family). When trying to query a Wikibase item in the item namespace (860), this error is raised: AttributeError: 'NoneType' object has no attribute 'item_namespace'.

I have looked in the ManageWiki interface, but there's no way of setting a namespace as an "item namespace". Thanks in advance for your help!

Event Timeline

NeoMahler created this task.Aug 13 2020, 15:28

Could you paste the exact script + config you have with any passwords removed?

Sure! This is the script:

import pywikibot
site = pywikibot.Site("en", "nbdb")
repo = site.data_repository()
item = pywikibot.ItemPage(repo, u"Q165")
claim = pywikibot.Claim(repo, u'P15')
target = pywikibot.ItemPage(repo, u"Q6")
claim.setTarget(target)
item.addClaim(claim, summary=u'Adding claim')

I generated the user-config file automatically. The relevant lines are:

family = 'nbdb'
mylang = 'en'
usernames['nbdb']['en'] = 'BinaryBot'

(full user-config.py: https://hastebin.com/ohezobitar.py)

The family file (also automatically) is:

# -*- coding: utf-8 -*-
"""
This family file was auto-generated by generate_family_file.py script.

Configuration parameters:
  url = https://data.nonbinary.wiki/wiki/Main_Page
  name = nbdb

Please do not commit this to the Git repository!
"""
from pywikibot import family
from pywikibot.tools import deprecated


class Family(family.Family):  # noqa: D101

    name = 'nbdb'
    langs = {
        'en': 'data.nonbinary.wiki',
    }

    def scriptpath(self, code):
        return {
            'en': '/w',
        }[code]

    @deprecated('APISite.version()', since='20141225')
    def version(self, code):
        return {
            'en': '1.34.2',
        }[code]

    def protocol(self, code):
        return {
            'en': 'https',
        }[code]

Finally, this is the full traceback:

Traceback (most recent call last):
  File "c:/Users/ondo/Documents/NBW-NBDb/core/nbdb_test.py", line 4, in <module>
    item = pywikibot.ItemPage(repo, u"Q165")
  File "c:\Users\ondo\Documents\NBW-NBDb\core\pywikibot\page\__init__.py", line 4588, in __init__
    ns = site.item_namespace
AttributeError: 'NoneType' object has no attribute 'item_namespace'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>