#!/usr/bin/python3
import pywikibot
site = pywikibot.Site("en", "wikipedia")
site
APISite("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)
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-7-db4ef6ff8b31> in <module>()
----> 1 item = pywikibot.ItemPage.fromPage(page)

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in fromPage(cls, page, lazy_load)
   3909         i._site = page.site
   3910         i._title = page.title(withSection=False)
-> 3911         if not lazy_load and not i.exists():
   3912             raise pywikibot.NoPage(i)
   3913         return i

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in exists(self)
   3457         if not hasattr(self, '_content'):
   3458             try:
-> 3459                 self.get()
   3460                 return True
   3461             except pywikibot.NoPage:

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in get(self, force, get_redirect, *args, **kwargs)
   3924         @raise NotImplementedError: a value in args or kwargs
   3925         """
-> 3926         data = super(ItemPage, self).get(force, *args, **kwargs)
   3927 
   3928         if self.isRedirectPage() and not get_redirect:

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in get(self, force, *args, **kwargs)
   3539                 self.claims[pid] = []
   3540                 for claim in self._content['claims'][pid]:
-> 3541                     c = Claim.fromJSON(self.repo, claim)
   3542                     c.on_item = self
   3543                     self.claims[pid].append(c)

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in fromJSON(cls, site, data)
   4335             # The default covers string, url types
   4336             claim.target = Claim.TARGET_CONVERTER.get(
-> 4337                 claim.type, lambda value, site: value)(value, site)
   4338         if 'rank' in data:  # References/Qualifiers don't have ranks
   4339             claim.rank = data['rank']

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in <lambda>(value, site)
   4275             ItemPage(site, 'Q' + str(value['numeric-id'])),
   4276         'commonsMedia': lambda value, site:
-> 4277             FilePage(pywikibot.Site('commons', 'commons'), value),
   4278         'globe-coordinate': pywikibot.Coordinate.fromWikibase,
   4279         'time': lambda value, site: pywikibot.WbTime.fromWikibase(value),

/srv/paws/lib/python3.4/site-packages/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1415                              cls, depth)
   1416                     del __kw[old_arg]
-> 1417             return obj(*__args, **__kw)
   1418 
   1419         if not __debug__:

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in __init__(self, source, title)
   2300         """Constructor."""
   2301         self._file_revisions = {}  # dictionary to cache File history.
-> 2302         super(FilePage, self).__init__(source, title, 6)
   2303         if self.namespace() != 6:
   2304             raise ValueError(u"'%s' is not in the file namespace!" % title)

/srv/paws/lib/python3.4/site-packages/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1415                              cls, depth)
   1416                     del __kw[old_arg]
-> 1417             return obj(*__args, **__kw)
   1418 
   1419         if not __debug__:

/srv/paws/lib/python3.4/site-packages/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1415                              cls, depth)
   1416                     del __kw[old_arg]
-> 1417             return obj(*__args, **__kw)
   1418 
   1419         if not __debug__:

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in __init__(self, source, title, ns)
   2176                 raise ValueError(u'Title must be specified and not empty '
   2177                                  'if source is a Site.')
-> 2178         super(Page, self).__init__(source, title, ns)
   2179 
   2180     @deprecate_arg("get_redirect", None)

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in __init__(self, source, title, ns)
    158 
    159         if isinstance(source, pywikibot.site.BaseSite):
--> 160             self._link = Link(title, source=source, defaultNamespace=ns)
    161             self._revisions = {}
    162         elif isinstance(source, Page):

/srv/paws/lib/python3.4/site-packages/pywikibot/page.py in __init__(self, text, source, defaultNamespace)
   4942         # See bug T104864, defaultNamespace might have been deleted.
   4943         try:
-> 4944             self._defaultns = self._source.namespaces[defaultNamespace]
   4945         except KeyError:
   4946             self._defaultns = defaultNamespace

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

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in _build_namespaces(self)
   2587         # For versions lower than 1.14, APISite needs to override
   2588         # the defaults defined in Namespace.
-> 2589         is_mw114 = MediaWikiVersion(self.version()) >= MediaWikiVersion('1.14')
   2590 
   2591         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in version(self)
   2694         if not version:
   2695             try:
-> 2696                 version = self.siteinfo.get('generator', expiry=1).split(' ')[1]
   2697             except pywikibot.data.api.APIError:
   2698                 # May occur if you are not logged in (no API read permissions).

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in get(self, key, get_default, cache, expiry)
   1653                 elif not Siteinfo._is_expired(cached[1], expiry):
   1654                     return copy.deepcopy(cached[0])
-> 1655         preloaded = self._get_general(key, expiry)
   1656         if not preloaded:
   1657             preloaded = self._get_siteinfo(key, expiry)[key]

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in _get_general(self, key, expiry)
   1599                         u"', '".join(props)), _logger)
   1600             props += ['general']
-> 1601             default_info = self._get_siteinfo(props, expiry)
   1602             for prop in props:
   1603                 self._cache[prop] = default_info[prop]

/srv/paws/lib/python3.4/site-packages/pywikibot/site.py in _get_siteinfo(self, prop, expiry)
   1525             # warnings are handled later
   1526             request._warning_handler = warn_handler
-> 1527             data = request.submit()
   1528         except api.APIError as e:
   1529             if e.code == 'siunknown_siprop':

/srv/paws/lib/python3.4/site-packages/pywikibot/data/api.py in submit(self)
   2339         cached_available = self._load_cache()
   2340         if not cached_available:
-> 2341             self._data = super(CachedRequest, self).submit()
   2342             self._write_cache(self._data)
   2343         else:

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

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