Handle missing login email

This commit is contained in:
2025-12-21 18:35:20 +01:00
parent fe7f7adb0c
commit 5711bf39ab
2 changed files with 18 additions and 4 deletions

View File

@@ -149,8 +149,15 @@ class ClientWrapper:
code_type = getattr(sent, "type", None) code_type = getattr(sent, "type", None)
logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown") logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown")
if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired): if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired):
logger.warning("Telegram requires login email verification; sending email code") logger.warning("Telegram requires login email verification")
sent = await self.client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) 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) code_type = getattr(sent, "type", None)
logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown") logger.info("Login code type: %s", type(code_type).__name__ if code_type else "unknown")
if isinstance(code_type, types.auth.SentCodeTypeEmailCode): if isinstance(code_type, types.auth.SentCodeTypeEmailCode):

View File

@@ -51,8 +51,15 @@ async def generate(args: argparse.Namespace) -> None:
code_type = getattr(sent, "type", None) code_type = getattr(sent, "type", None)
print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}") print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}")
if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired): if isinstance(code_type, types.auth.SentCodeTypeSetUpEmailRequired):
print("Telegram requires login email verification, sending email code...") print("Telegram requires login email verification.")
sent = await client(functions.auth.ResetLoginEmailRequest(phone, sent.phone_code_hash)) 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) code_type = getattr(sent, "type", None)
print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}") print(f"Code delivery type: {type(code_type).__name__ if code_type else 'unknown'}")
if isinstance(code_type, types.auth.SentCodeTypeEmailCode): if isinstance(code_type, types.auth.SentCodeTypeEmailCode):