Page MenuHomePhabricator

When I read the page, I get "API error mwoauth-invalid-authorization...."
Closed, ResolvedPublicBUG REPORT

Description

In my Notebook I read the page:

import pywikibot
site = pywikibot.Site('uk', 'wikipedia')
page = pywikibot.Page(site, 'Користувач:Klip game/Чернетка')
print(page.text)

And I get: "WARNING: API error mwoauth-invalid-authorization: The authorization headers in your request are not valid: No approved grant was found for that authorization token."

There was no such error yesterday. I checked permissions in OAuth - nothing is disabled.
I found tickets T216722 and T168222. They advise try to login to commons and wikidata as well. I did this, reconnected to PAWS, but the problem remained.

Event Timeline

Hi! When I'm running your code it seems to work:

@PAWS:~/pwb-test$ pwb.py page.py 
Hello
Hello
@PAWS:~/pwb-test$ cat page.py 
import pywikibot
site = pywikibot.Site('uk', 'wikipedia')
page = pywikibot.Page(site, 'Користувач:Klip game/Чернетка')
print(page.text)

How are you running the script?

How are you running the script?

As my Notebook, not running as script. I tried to run from the terminal as a script. Here is the result:

@PAWS:~$ pwb.py test.py 
WARNING: API error mwoauth-invalid-authorization: The authorization headers in your request are not valid: No approved grant was found for that authorization token.
Traceback (most recent call last):
  File "/srv/paws/pwb/pwb.py", line 39, in <module>
    sys.exit(main())
  File "/srv/paws/pwb/pwb.py", line 35, in main
    runpy.run_path(str(path), run_name='__main__')
  File "/usr/lib/python3.10/runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 516, in <module>
    main()
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 500, in main
    if not execute():
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 487, in execute
    run_python_file(filename, script_args, module)
  File "/srv/paws/pwb/pywikibot/scripts/wrapper.py", line 147, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File "test.py", line 4, in <module>
    print(page.text)
  File "/srv/paws/pwb/pywikibot/page/_page.py", line 548, in text
    return self.get(get_redirect=True)
  File "/srv/paws/pwb/pywikibot/page/_page.py", line 397, in get
    self._getInternals()
  File "/srv/paws/pwb/pywikibot/page/_page.py", line 436, in _getInternals
    self.site.loadrevisions(self, content=True)
  File "/srv/paws/pwb/pywikibot/site/_generators.py", line 722, in loadrevisions
    'rvprop': self._rvprops(content=content),
  File "/srv/paws/pwb/pywikibot/site/_generators.py", line 636, in _rvprops
    if self.mw_version >= '1.32':
  File "/srv/paws/pwb/pywikibot/site/_apisite.py", line 1151, in mw_version
    mw_ver = MediaWikiVersion(self.version())
  File "/srv/paws/pwb/pywikibot/site/_apisite.py", line 1124, in version
    version = self.siteinfo.get('generator', expiry=1).split(' ')[1]
  File "/srv/paws/pwb/pywikibot/site/_siteinfo.py", line 304, in get
    preloaded = self._get_general(key, expiry)
  File "/srv/paws/pwb/pywikibot/site/_siteinfo.py", line 242, in _get_general
    default_info = self._get_siteinfo(props, expiry)
  File "/srv/paws/pwb/pywikibot/site/_siteinfo.py", line 167, in _get_siteinfo
    data = request.submit()
  File "/srv/paws/pwb/pywikibot/data/api/_requests.py", line 1264, in submit
    self._data = super().submit()
  File "/srv/paws/pwb/pywikibot/data/api/_requests.py", line 1061, in submit
    raise NoUsernameError('Failed OAuth authentication for {}: {}'
pywikibot.exceptions.NoUsernameError: Failed OAuth authentication for wikipedia:uk: The authorization headers in your request are not valid: No approved grant was found for that authorization token.
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.NoUsernameError'>
@PAWS:~$

Isn't this T252306? :)

No, there is a problem in the availability of registration on the site, I do not have this problem. On February 25 everything worked.

Curious, it still seems to be working for me when I run it in a python notebook:

https://public-paws.wmcloud.org/User:VRook_(WMF)/page.ipynb

@Klip_game Maybe it is a login issue with PAWS. Could you try running it from the new cluster hub-paws.wmcloud.org (I'm not really expecting much as I tried it from both the new and old, and both seemed to work, so I apologize, but I'm grasping at straws :)

And maybe stop your server on paws, and log out of paws, and back into paws?

@Klip_game Maybe it is a login issue with PAWS. Could you try running it from the new cluster hub-paws.wmcloud.org (I'm not really expecting much as I tried it from both the new and old, and both seemed to work, so I apologize, but I'm grasping at straws :)

Marvelous! You were right. Everything works on the new cluster. Thanks a lot for the tip.

Awesome! Glad to hear it's working :)