Handle login email requirement
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
||||
|
||||
from telethon import TelegramClient
|
||||
from telethon.errors import SessionPasswordNeededError
|
||||
from telethon.tl import functions, types
|
||||
from telethon.sessions import StringSession
|
||||
|
||||
|
||||
@@ -49,6 +50,13 @@ async def generate(args: argparse.Namespace) -> None:
|
||||
sent = await client.send_code_request(phone, force_sms=args.sms)
|
||||
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))
|
||||
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):
|
||||
print("Check your email for the login code.")
|
||||
code = input("Enter the code you received: ").strip()
|
||||
try:
|
||||
await client.sign_in(phone=phone, code=code, phone_code_hash=sent.phone_code_hash)
|
||||
|
||||
Reference in New Issue
Block a user