import pywikibot
site = pywikibot.Site('test', 'wikipedia')
site
APISite("test", "wikipedia")
page = pywikibot.Page(site, 'test')
page.exists()
True
page.text
'Heippa maailma 2019-10-13 08:07:10.337828\n\n== Testing ==\n\ncross-origin edit\n\n== Testing ==\n\ncross-origin edit\n\n== Testing ==\n\ncross-origin edit'
page.text = 'Hello world'
page.save()
Page [[Test]] saved
page.text
'Hello world'
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-10-fdd0db31b3b1> in <module>
      3 site = pywikibot.Site("en", "wikipedia")
      4 page = pywikibot.Page(site, "Douglas Adams")
----> 5 item = pywikibot.ItemPage.fromPage(page)
      6 
      7 print(item)

/srv/paws/pwb/pywikibot/page.py in fromPage(cls, page, lazy_load)
   4426             page._item = cls(repo, page.properties().get('wikibase_item'))
   4427             return page._item
-> 4428         i = cls(repo)
   4429         # clear id, and temporarily store data needed to lazy loading the item
   4430         del i.id

/srv/paws/pwb/pywikibot/page.py in __init__(self, site, title, ns)
   4347         """
   4348         if ns is None:
-> 4349             ns = site.item_namespace
   4350         # Special case for empty item.
   4351         if title is None or title == '-1':

/srv/paws/pwb/pywikibot/site.py in item_namespace(self)
   7517         """
   7518         if self._item_namespace is None:
-> 7519             self._cache_entity_namespaces()
   7520 
   7521         if isinstance(self._item_namespace, Namespace):

/srv/paws/pwb/pywikibot/site.py in _cache_entity_namespaces(self)
   7498         self._property_namespace = False
   7499 
-> 7500         for namespace in self.namespaces.values():
   7501             if not hasattr(namespace, 'defaultcontentmodel'):
   7502                 continue

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

/srv/paws/pwb/pywikibot/site.py in _build_namespaces(self)
   2638         _namespaces = {}
   2639 
-> 2640         for nsdata in self.siteinfo.get('namespaces', cache=False).values():
   2641             ns = nsdata.pop('id')
   2642             custom_name = None

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

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

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

/srv/paws/pwb/pywikibot/data/api.py in submit(self)
   2232         cached_available = self._load_cache()
   2233         if not cached_available:
-> 2234             self._data = super(CachedRequest, self).submit()
   2235             self._write_cache(self._data)
   2236         else:

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

NoUsername: Failed OAuth authentication for wikidata:wikidata: The authorization headers in your request are for a user that does not exist here
import pywikibot
site = pywikibot.Site("en", "wikipedia")
page = pywikibot.Page(site, "Douglas Adams")
item = pywikibot.ItemPage.fromPage(page)
---------------------------------------------------------------------------
EntityTypeUnknownException                Traceback (most recent call last)
<ipython-input-14-f05e03dbefcc> in <module>
----> 1 item = pywikibot.ItemPage.fromPage(page)

/srv/paws/pwb/pywikibot/page.py in fromPage(cls, page, lazy_load)
   4426             page._item = cls(repo, page.properties().get('wikibase_item'))
   4427             return page._item
-> 4428         i = cls(repo)
   4429         # clear id, and temporarily store data needed to lazy loading the item
   4430         del i.id

/srv/paws/pwb/pywikibot/page.py in __init__(self, site, title, ns)
   4347         """
   4348         if ns is None:
-> 4349             ns = site.item_namespace
   4350         # Special case for empty item.
   4351         if title is None or title == '-1':

/srv/paws/pwb/pywikibot/site.py in item_namespace(self)
   7524             raise EntityTypeUnknownException(
   7525                 '%r does not support entity type "item"'
-> 7526                 % self)
   7527 
   7528     @property

EntityTypeUnknownException: DataSite("wikidata", "wikidata") does not support entity type "item"
print(item)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-b37b2286ac42> in <module>
----> 1 print(item)

NameError: name 'item' is not defined