From 5711bf39ab6856ec7aed43183ede11eab76a3011 Mon Sep 17 00:00:00 2001 From: overspend1 Date: Sun, 21 Dec 2025 18:35:20 +0100 Subject: [PATCH] Handle missing login email --- core/client.py | 11 +++++++++-- scripts/generate-session-string.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/client.py b/core/client.py index facf9b0..cde2cde 100644 --- a/core/client.py +++ b/core/client.py @@ -149,8 +149,15 @@ class ClientWrapper: code_type = getattr(sent, "type", None) logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown") if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired): - logger.warning("Telegram requires login email verification; sending email code") - sent = await self.client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) + logger.warning("Telegram requires login email verification") + try: + sent = await self.client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) + except Exception as exc: + logger.error("Email reset failed: %s", exc) + raise RuntimeError( + "Set a recovery email in Telegram (Settings -> Privacy and Security -> Two-Step Verification) " + "then retry login." + ) from exc code_type = getattr(sent, "type", None) logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown") if isinstance(code_type, types.auth.SentCodeTypeEmailCode): diff --git a/scripts/generate-session-string.py b/scripts/generate-session-string.py index c934c4a..4f07318 100644 --- a/scripts/generate-session-string.py +++ b/scripts/generate-session-string.py @@ -51,8 +51,15 @@ async def generate(args: argparse.Namespace) -> None: code_type = getattr(sent, "type", None) print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}") if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired): - print("Telegram requires login email verification, sending email code...") - sent = await client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) + print("Telegram requires login email verification.") + try: + sent = await client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) + except Exception as exc: + print(f"Email reset failed: {exc}") + print("Open Telegram -> Settings -> Privacy and Security -> Two-Step Verification") + print("Add and verify a recovery email, then retry.") + await client.disconnect() + return code_type = getattr(sent, "type", None) print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}") if isinstance(code_type, types.auth.SentCodeTypeEmailCode):