import pywikibot
from pywikibot import pagegenerators as pg
def list_template_usage(site_obj, tmpl_name):
    name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
    tmpl_page = pywikibot.Page(site_obj, name)
    ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)
    filter_gen = pg.NamespaceFilterPageGenerator(ref_gen, namespaces=[0])
    generator = site_obj.preloadpages(filter_gen, pageprops=True)
    return generator
site = pywikibot.Site("pt", 'wikipedia')
tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
for page in tmpl_gen:
    print(page.title())
WARNING: API error mwoauth-invalid-authorization-invalid-user: The authorization headers in your request are for a user that does not exist here
---------------------------------------------------------------------------
NoUsername                                Traceback (most recent call last)
<ipython-input-5-b0cd84d028a1> in <module>()
      9     return generator
     10 site = pywikibot.Site("pt", 'wikipedia')
---> 11 tmpl_gen = list_template_usage(site, "Infobox meteorietinslag")
     12 for page in tmpl_gen:
     13     print(page.title())

<ipython-input-5-b0cd84d028a1> in list_template_usage(site_obj, tmpl_name)
      2 from pywikibot import pagegenerators as pg
      3 def list_template_usage(site_obj, tmpl_name):
----> 4     name = "{}:{}".format(site_obj.namespace(10), tmpl_name)
      5     tmpl_page = pywikibot.Page(site_obj, name)
      6     ref_gen = pg.ReferringPageGenerator(tmpl_page, onlyTemplateInclusion=True)

/srv/paws/pwb/pywikibot/site.py in namespace(self, num, all)
   2959         if all:
   2960             return self.namespaces[num]
-> 2961         return self.namespaces[num][0]
   2962 
   2963     @deprecated('version()', since='20140612')

/srv/paws/pwb/pywikibot/site.py in namespaces(self)
   1021         """Return dict of valid namespaces on this wiki."""
   1022         if not hasattr(self, '_namespaces'):
-> 1023             self._namespaces = NamespacesDict(self._build_namespaces())
   1024         return self._namespaces
   1025 

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2643         # For versions lower than 1.14, APISite needs to override
   2644         # the defaults defined in Namespace.
-> 2645         is_mw114 = self.mw_version >= '1.14'
   2646 
   2647         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/pwb/pywikibot/site.py in mw_version(self)
   2777         mw_ver, cache_time = getattr(self, '_mw_version_time', (None, None))
   2778         if mw_ver is None or time.time() - cache_time > 60 * 60 * 24:
-> 2779             mw_ver = MediaWikiVersion(self.version())
   2780             setattr(self, '_mw_version_time', (mw_ver, time.time()))
   2781         return mw_ver

/srv/paws/pwb/pywikibot/site.py in version(self)
   2760             try:
   2761                 version = self.siteinfo.get('generator',
-> 2762                                             expiry=1).split(' ')[1]
   2763             except pywikibot.data.api.APIError:
   2764                 # May occur if you are not logged in (no API read permissions).

/srv/paws/pwb/pywikibot/site.py in get(self, key, get_default, cache, expiry)
   1670                 elif not Siteinfo._is_expired(cached[1], expiry):
   1671                     return copy.deepcopy(cached[0])
-> 1672         preloaded = self._get_general(key, expiry)
   1673         if not preloaded:
   1674             preloaded = self._get_siteinfo(key, expiry)[key]

/srv/paws/pwb/pywikibot/site.py in _get_general(self, key, expiry)
   1616                     .format("', '".join(props)), _logger)
   1617             props += ['general']
-> 1618             default_info = self._get_siteinfo(props, expiry)
   1619             for prop in props:
   1620                 self._cache[prop] = default_info[prop]

/srv/paws/pwb/pywikibot/site.py in _get_siteinfo(self, prop, expiry)
   1539         request._warning_handler = warn_handler
   1540         try:
-> 1541             data = request.submit()
   1542         except api.APIError as e:
   1543             if e.code == 'siunknown_siprop':

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2426         cached_available = self._load_cache()
   2427         if not cached_available:
-> 2428             self._data = super(CachedRequest, self).submit()
   2429             self._write_cache(self._data)
   2430         else:

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2253                     continue
   2254                 raise NoUsername('Failed OAuth authentication for %s: %s'
-> 2255                                  % (self.site, info))
   2256             if code == 'cirrussearch-too-busy-error':  # T170647
   2257                 self.wait()

NoUsername: Failed OAuth authentication for wikipedia:pt: The authorization headers in your request are for a user that does not exist here