chairemobilite / transition_qgis

MIT License
1 stars 4 forks source link

Error when loading plugin after a token expired #18

Closed greenscientist closed 5 months ago

greenscientist commented 5 months ago

I'm getting a stack trace, from what I understand is an expired token:

2024-05-27T15:51:21 WARNING Traceback (most recent call last): File "/home/scientist/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Transition-QGIS/transition_qgis.py", line 272, in show_dockwidget self.scenarios = self.transition_instance.get_scenarios() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/scientist/.local/lib/python3.11/site-packages/pyTransition/transition.py", line 168, in get_scenarios response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://chaire.transition.city/api/v1/scenarios

         During handling of the above exception, another exception occurred:

         Traceback (most recent call last):
          File "/home/scientist/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Transition-QGIS/transition_qgis.py", line 231, in run
          self.show_dockwidget()
          File "/home/scientist/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Transition-QGIS/transition_qgis.py", line 316, in show_dockwidget
          self.handleExpiredToken()
          File "/home/scientist/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Transition-QGIS/transition_qgis.py", line 622, in handleExpiredToken
          self.onClosePlugin()
          File "/home/scientist/.local/share/QGIS/QGIS3/profiles/default/python/plugins/Transition-QGIS/transition_qgis.py", line 208, in onClosePlugin
          self.dockwidget.closingPlugin.disconnect(self.onClosePlugin)
         TypeError: 'method' object is not connected
greenscientist commented 5 months ago

In checkValidLogin, we don't actually validate that the Token is valid. The Transition class constructor does not check it.

    def checkValidLogin(self):
        """Check if there is a login token in the settings"""
        token = self.settings.value("token")
        if token:
            self.transition_instance = Transition(self.settings.value("url"), None, None, self.settings.value("token"))
            return True

        return False
greenscientist commented 5 months ago

(C'est tangentiel, mais on manque de catch d'exception un peu partout :) )

tahini commented 5 months ago

iirc Je pensais que c'était la lib qui, si le token est expiré, refaisait une requête pour un nouveau? (qu'on ne catch probablement pas dans Qgis, de sorte qu'on utilise quand même l'ancien?)

greenscientist commented 5 months ago

La lib ne fait pas ça. Peut-etre qu'une version antérieur le faisait.