Page MenuHomePhabricator

TestSupersetWithAuth.test_login_and_oauth_permission tests of superset_tests fails
Open, HighPublicBUG REPORT

Description

TestSupersetWithAuth.test_login_and_oauth_permission tests of superset_tests fails recently during login with TooManyRedirect exception for all Python versions

_____________ TestSupersetWithAuth.test_login_and_oauth_permission _____________

self = <tests.superset_tests.TestSupersetWithAuth testMethod=test_login_and_oauth_permission>

    def test_login_and_oauth_permission(self):
        """Superset login and queries."""
        sql = 'SELECT page_id, page_title FROM page LIMIT 2;'
        site = self.get_site()
    
        # Test login and initial site parameters
        superset = SupersetQuery(site=site)
        try:
>           superset.login()

tests/superset_tests.py:65: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywikibot/data/superset.py:88: in login
    self.last_response = http.fetch(url)
pywikibot/comms/http.py:452: in fetch
    callback(response)
pywikibot/comms/http.py:338: in error_handling_callback
    raise response from None
pywikibot/comms/http.py:443: in fetch
    response = session.request(method, uri,
/opt/hostedtoolcache/PyPy/3.8.16/x64/lib/pypy3.8/site-packages/requests/sessions.py:589: in request
    resp = self.send(prep, **send_kwargs)
/opt/hostedtoolcache/PyPy/3.8.16/x64/lib/pypy3.8/site-packages/requests/sessions.py:724: in send
    history = [resp for resp in gen]
/opt/hostedtoolcache/PyPy/3.8.16/x64/lib/pypy3.8/site-packages/requests/sessions.py:724: in <listcomp>
    history = [resp for resp in gen]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <requests.sessions.Session object at 0x0000000031b3aec8>
resp = <Response [302]>, req = <PreparedRequest [GET]>, stream = False
timeout = (6.05, 45), verify = True, cert = None, proxies = OrderedDict()
yield_requests = False, adapter_kwargs = {}
hist = [<Response [302]>, <Response [307]>, <Response [302]>, <Response [307]>, <Response [302]>, <Response [307]>, ...]
url = 'https://meta.wikimedia.org/w/rest.php/oauth2/authorize?client_id=***<redacted>&redirect_uri=https%...honlyprivate&state=***'
previous_fragment = '', prepared_request = <PreparedRequest [GET]>
parsed_rurl = ParseResult(scheme='https', netloc='meta.wikimedia.org', path='/w/rest.php/oauth2/authorize', params='', query='client...tate=***', fragment='')
parsed = ParseResult(scheme='https', netloc='meta.wikimedia.org', path='/w/index.php', params='', query='title=Special:OAuth/ap...IZZqB_CTnW6Nmt8&client_id=***<redacted>&oauth_version=2&scope=mwoauth-authonlyprivate', fragment='')
purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding')

    def resolve_redirects(
        self,
        resp,
        req,
        stream=False,
        timeout=None,
        verify=True,
        cert=None,
        proxies=None,
        yield_requests=False,
        **adapter_kwargs,
    ):
        """Receives a Response. Returns a generator of Responses or Requests."""
    
        hist = []  # keep track of history
    
        url = self.get_redirect_target(resp)
        previous_fragment = urlparse(req.url).fragment
        while url:
            prepared_request = req.copy()
    
            # Update history and keep track of redirects.
            # resp.history must ignore the original request in this loop
            hist.append(resp)
            resp.history = hist[1:]
    
            try:
                resp.content  # Consume socket so it can be released
            except (ChunkedEncodingError, ContentDecodingError, RuntimeError):
                resp.raw.read(decode_content=False)
    
            if len(resp.history) >= self.max_redirects:
>               raise TooManyRedirects(
                    f"Exceeded {self.max_redirects} redirects.", response=resp
                )
E               requests.exceptions.TooManyRedirects: Exceeded 30 redirects.

/opt/hostedtoolcache/PyPy/3.8.16/x64/lib/pypy3.8/site-packages/requests/sessions.py:191: TooManyRedirects

Event Timeline

Xqt triaged this task as High priority.May 30 2025, 11:16 AM
Xqt changed the subtype of this task from "Task" to "Bug Report".
Xqt moved this task from Backlog to Test failures on the Pywikibot-tests board.

Not sure if this same, but I noticed yesterday that I could not login to "meta" using pywikibot. When I try to login, it will ask verification code sent to email. I will get that, but when I submit it then login fails with "Invalid verification code!". This same causes also superset code fail as it uses meta.wikimedia.org for authentication.

Pywikibot version : pywikibot-10.1.0 (OS X 15.5 (24F74) )

Code:

import pywikibot
loginsite = pywikibot.Site('meta')
loginsite.login()

Output.

(venv) wiki@Wikis-MacBook-Air publicart % python test1.py
/Users/wiki/publicart/venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
Password for user Zache-test on meta:meta (no characters will be shown): 
You need to verify your login. A verification code has been sent to your email address, please enter that code here.: 
WARNING: API warning (main): Unrecognized parameter: OATHToken.
Invalid verification code!: 
Traceback (most recent call last):
  File "/Users/wiki/publicart/test1.py", line 3, in <module>
    loginsite.login()
  File "/Users/wiki/publicart/venv/lib/python3.9/site-packages/pywikibot/site/_apisite.py", line 426, in login
    if login_manager.login(retry=True, autocreate=autocreate):
  File "/Users/wiki/publicart/venv/lib/python3.9/site-packages/pywikibot/login.py", line 299, in login
    self.login_to_site()
  File "/Users/wiki/publicart/venv/lib/python3.9/site-packages/pywikibot/login.py", line 443, in login_to_site
    del login_request['username']
  File "/Users/wiki/publicart/venv/lib/python3.9/site-packages/pywikibot/data/api/_requests.py", line 385, in __delitem__
    del self._params[key]
KeyError: 'username'
CRITICAL: Exiting due to uncaught exception KeyError: 'username'

Thanks for that hint but I changed pywikibot-test account to use bot passwords due to T395264. I am not sure if the new bot password works with all tests but other login/logout tests does, see https://github.com/wikimedia/pywikibot/actions

Anyway I try to implement email verification soon which should work similar to 2FA-login (see https://doc.wikimedia.org/pywikibot/master/api_ref/login.html#login.ClientLoginManager)

Login to fiwiki and commonswiki worked, but they didin't require the verification code for login. Only meta.wikimedia.org wanted verification code.

Login to fiwiki and commonswiki worked, but they didin't require the verification code for login. Only meta.wikimedia.org wanted verification code.

I implemented a patch for email verification due to T395703 in https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1152397

The error message above looks like a temporary issue (TEMPORARY_REDIRECT):
[<Response [302]>, <Response [307]>, <Response [302]>, <Response [307]>, <Response [302]>, <Response [307]>, ...]

Change #1152398 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] tests: Temporary let TestSupersetWithAuth.test_login_and_oauth_permission fail

https://gerrit.wikimedia.org/r/1152398

Change #1152398 merged by jenkins-bot:

[pywikibot/core@master] tests: Temporary let TestSupersetWithAuth.test_login_and_oauth_permission fail

https://gerrit.wikimedia.org/r/1152398

Change #1195382 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] tests: test supertest with Pywikibot-oauth account

https://gerrit.wikimedia.org/r/1195382

Change #1195382 merged by jenkins-bot:

[pywikibot/core@master] tests: test supertest with Pywikibot-oauth account

https://gerrit.wikimedia.org/r/1195382