Untitled
unknown
plain_text
a year ago
1.5 kB
8
Indexable
def connect_to_wifi(self):
ssid = self.selected_network.get()
password = self.password.get()
if not ssid:
self.status_message.set("Please select a Wi-Fi network.")
return
self.status_message.set(f"Connecting to {ssid}...")
self.update()
try:
while True:
result = subprocess.run(
["nmcli", "dev", "wifi", "connect", ssid, "password", password],
capture_output=True, text=True
)
if result.returncode == 0:
self.status_message.set(f"Successfully connected to {ssid}.")
self.update_current_connection()
break
else:
error_message = result.stderr.strip()
# Custom error handling for common scenarios
if "802-11-wireless-security.psk: property is invalid" in error_message:
self.status_message.set("Incorrect password. Please try again.")
elif "No network with SSID" in error_message:
self.status_message.set("The selected Wi-Fi network is unavailable.")
else:
self.status_message.set(f"Connection failed: {error_message}")
# Reset password field and prompt user again
self.reset_password()
self.password_entry.focus()
return
except Exception as e:
self.status_message.set(f"Error: {e}")
Editor is loading...
Leave a Comment