import mwapi
session = mwapi.Session('https://en.wikipedia.org', user_agent='Google') #TODO add user agent
Sending requests with default User-Agent.  Set 'user_agent' on mwapi.Session to quiet this message.
print(session.get(action='query', meta='userinfo'))
{'batchcomplete': '', 'query': {'userinfo': {'id': 0, 'name': '10.68.17.185', 'anon': ''}}}
site = mwapi.site('en.wikipedia.org')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-68362a591449> in <module>()
----> 1 site = mwapi.site('en.wikipedia.org')

AttributeError: module 'mwapi' has no attribute 'site'
import requests
api_url = 'https://en.wikipedia.org/w/api.php'
import pywikibot
site = pywikibot.Site()
page = pywikibot.Page(site, u"India")
text = page.text
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-11-b03cdaaeb454> in <module>()
      1 site = pywikibot.Site()
----> 2 page = pywikibot.Page(site, u"India")
      3 text = page.text

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1714                              cls, depth)
   1715                     del __kw[old_arg]
-> 1716             return obj(*__args, **__kw)
   1717 
   1718         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in __init__(self, source, title, ns)
   2273                 raise ValueError('Title must be specified and not empty '
   2274                                  'if source is a Site.')
-> 2275         super(Page, self).__init__(source, title, ns)
   2276 
   2277     @property

/srv/paws/pwb/pywikibot/page.py in __init__(self, source, title, ns)
    194 
    195         if isinstance(source, pywikibot.site.BaseSite):
--> 196             self._link = Link(title, source=source, default_namespace=ns)
    197             self._revisions = {}
    198         elif isinstance(source, Page):

/srv/paws/pwb/pywikibot/tools/__init__.py in wrapper(*__args, **__kw)
   1714                              cls, depth)
   1715                     del __kw[old_arg]
-> 1716             return obj(*__args, **__kw)
   1717 
   1718         if not __debug__:

/srv/paws/pwb/pywikibot/page.py in __init__(self, text, source, default_namespace)
   5505         # See bug T104864, default_namespace might have been deleted.
   5506         try:
-> 5507             self._defaultns = self._source.namespaces[default_namespace]
   5508         except KeyError:
   5509             self._defaultns = default_namespace

/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)
   2645         # For versions lower than 1.14, APISite needs to override
   2646         # the defaults defined in Namespace.
-> 2647         is_mw114 = self.mw_version >= '1.14'
   2648 
   2649         for nsdata in self.siteinfo.get('namespaces', cache=False).values():

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

/srv/paws/pwb/pywikibot/site.py in version(self)
   2762             try:
   2763                 version = self.siteinfo.get('generator',
-> 2764                                             expiry=1).split(' ')[1]
   2765             except pywikibot.data.api.APIError:
   2766                 # 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)
   1671                 elif not Siteinfo._is_expired(cached[1], expiry):
   1672                     return copy.deepcopy(cached[0])
-> 1673         preloaded = self._get_general(key, expiry)
   1674         if not preloaded:
   1675             preloaded = self._get_siteinfo(key, expiry)[key]

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

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

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

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

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