#!/usr/bin/python3
import pywikibot

site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)

print(item)
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-1-014a8c73592d> in <module>()
      4 site = pywikibot.Site("en", "wikipedia")
      5 page = pywikibot.Page(site, "Douglas Adams")
----> 6 item = pywikibot.ItemPage.fromPage(page)
      7 
      8 print(item)

/srv/paws/pwb/pywikibot/page.py in fromPage(cls, page, lazy_load)
   4023             # we already have the id, so use it
   4024             return cls(repo, page.properties().get('wikibase_item'))
-> 4025         i = cls(repo)
   4026         # clear id, and temporarily store data needed to lazy loading the item
   4027         del i.id

/srv/paws/pwb/pywikibot/page.py in __init__(self, site, title, ns)
   3948         """
   3949         if ns is None:
-> 3950             ns = site.item_namespace
   3951         # Special case for empty item.
   3952         if title is None or title == '-1':

/srv/paws/pwb/pywikibot/site.py in item_namespace(self)
   7025         """
   7026         if self._item_namespace is None:
-> 7027             self._cache_entity_namespaces()
   7028 
   7029         if isinstance(self._item_namespace, Namespace):

/srv/paws/pwb/pywikibot/site.py in _cache_entity_namespaces(self)
   7006         self._property_namespace = False
   7007 
-> 7008         for namespace in self.namespaces.values():
   7009             if not hasattr(namespace, 'defaultcontentmodel'):
   7010                 continue

/srv/paws/pwb/pywikibot/site.py in namespaces(self)
   1012         """Return dict of valid namespaces on this wiki."""
   1013         if not hasattr(self, '_namespaces'):
-> 1014             self._namespaces = NamespacesDict(self._build_namespaces())
   1015         return self._namespaces
   1016 

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2610         # For versions lower than 1.14, APISite needs to override
   2611         # the defaults defined in Namespace.
-> 2612         is_mw114 = MediaWikiVersion(self.version()) >= MediaWikiVersion('1.14')
   2613 
   2614         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/pwb/pywikibot/site.py in version(self)
   2723         if not version:
   2724             try:
-> 2725                 version = self.siteinfo.get('generator', expiry=1).split(' ')[1]
   2726             except pywikibot.data.api.APIError:
   2727                 # 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)
   1674                 elif not Siteinfo._is_expired(cached[1], expiry):
   1675                     return copy.deepcopy(cached[0])
-> 1676         preloaded = self._get_general(key, expiry)
   1677         if not preloaded:
   1678             preloaded = self._get_siteinfo(key, expiry)[key]

/srv/paws/pwb/pywikibot/site.py in _get_general(self, key, expiry)
   1620                         u"', '".join(props)), _logger)
   1621             props += ['general']
-> 1622             default_info = self._get_siteinfo(props, expiry)
   1623             for prop in props:
   1624                 self._cache[prop] = default_info[prop]

/srv/paws/pwb/pywikibot/site.py in _get_siteinfo(self, prop, expiry)
   1546             # warnings are handled later
   1547             request._warning_handler = warn_handler
-> 1548             data = request.submit()
   1549         except api.APIError as e:
   1550             if e.code == 'siunknown_siprop':

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2340         cached_available = self._load_cache()
   2341         if not cached_available:
-> 2342             self._data = super(CachedRequest, self).submit()
   2343             self._write_cache(self._data)
   2344         else:

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2173                     continue
   2174                 raise NoUsername('Failed OAuth authentication for %s: %s'
-> 2175                                  % (self.site, info))
   2176             # raise error
   2177             try:

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