Page MenuHomeMiraheze

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


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")
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'


The family file (also automatically) is:

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

Configuration parameters:
  url =
  name = nbdb

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

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

    name = 'nbdb'
    langs = {
        'en': '',

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

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

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

Finally, this is the full traceback:

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