Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1202211?usp=email )

Change subject: Fix(superset): Prevent login loop with unsupported auth methods
......................................................................

Fix(superset): Prevent login loop with unsupported auth methods

Superset enters an HTTP redirect loop when
OAuth or BotPassword auth methods are used.
this PR introduces error handling by checking
for TooManyRedirects exception in the last response,
indicating a redirect loop and raise a UserRightsE` error.

Bug: T408287
Change-Id: I77f710bb195125ac50112bdec6d7c4b9ea707921
---
M pywikibot/data/superset.py
1 file changed, 12 insertions(+), 2 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved




diff --git a/pywikibot/data/superset.py b/pywikibot/data/superset.py
index 9f49509..0c72a79 100644
--- a/pywikibot/data/superset.py
+++ b/pywikibot/data/superset.py
@@ -13,9 +13,11 @@
 from textwrap import fill
 from typing import TYPE_CHECKING, Any

+import requests
+
 import pywikibot
 from pywikibot.comms import http
-from pywikibot.exceptions import NoUsernameError, ServerError
+from pywikibot.exceptions import NoUsernameError, ServerError, UserRightsError


 if TYPE_CHECKING:
@@ -88,7 +90,15 @@

         # Test if uset has been successfully logged in
         url = f'{self.superset_url}/api/v1/me/'
-        self.last_response = http.fetch(url)
+        try:
+            self.last_response = http.fetch(url)
+        except requests.TooManyRedirects:
+            raise UserRightsError(
+                'Superset authentication does not support OAuth'
+                ' or BotPassword. Please use standard username/password'
+                ' authentication in user-config.py:'
+                ' usernames["meta"]["meta"] = "WIKIMEDIA_USERNAME"'
+            )

         # Handle error cases
         if self.last_response.status_code == HTTPStatus.OK:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1202211?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I77f710bb195125ac50112bdec6d7c4b9ea707921
Gerrit-Change-Number: 1202211
Gerrit-PatchSet: 8
Gerrit-Owner: Ezra yendau <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: Zache-tool <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to