From 07e0193db57bc2702d9a2200276516b532845376 Mon Sep 17 00:00:00 2001 From: yannis300307 Date: Mon, 13 Nov 2023 15:05:38 +0100 Subject: [PATCH] Added debugging and error handling --- alcasar.py | 14 ++++++++++---- main.py | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/alcasar.py b/alcasar.py index 856fb7e..e659820 100644 --- a/alcasar.py +++ b/alcasar.py @@ -85,12 +85,18 @@ class Alcasar: def update_statut(self): """Update the connexion statut""" - data = self.ses.get("http://alcasar-0320002d.smile-education.fr:3990/json/status?callback=chilliJSON.reply") - statut = json.loads( - data.text[17:-1]) + try: + data = self.ses.get("http://alcasar-0320002d.smile-education.fr:3990/json/status?callback=chilliJSON.reply") + statut = json.loads( + data.text[17:-1]) + except requests.exceptions.RequestException: + self.connection_statut = False + return False, "" - self.connection_statut = statut["clientState"] + # Update statuts variables with new data + self.connection_statut = bool(statut["clientState"]) self.logout_url = statut["redir"]["logoutURL"] + return self.connection_statut, self.logout_url def disconnect(self): """Disconnect the user from the authentication service""" diff --git a/main.py b/main.py index 7346637..a191323 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ if __name__ == '__main__': print("Checking if the computer is connected on an Alcasar WI-FI...") if alcasar.detect(): print("Alcasar Detected! Connecting...") - result = alcasar.connect("BENDJEY", "Q8CSKR") + result = alcasar.connect("USERNAME", "PASSWORD") # Check result match result: @@ -23,3 +23,5 @@ if __name__ == '__main__': input("disconnect ?") alcasar.disconnect() + else: + print("Not detected")