mirror of
https://gitverse.ru/kpa39l/chronicle.nixg.ru.git
synced 2026-09-29 09:55:08 +00:00
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""
|
|
Simple Telethon auth test with flood wait handling.
|
|
"""
|
|
|
|
import asyncio
|
|
from telethon import TelegramClient
|
|
from telethon.errors import FloodWaitError, SessionPasswordNeededError
|
|
|
|
api_id = 24276216
|
|
api_hash = '2d6d0bb78f433bc5a086735c63e3958f'
|
|
phone = '+79284382181'
|
|
|
|
async def main():
|
|
client = TelegramClient(
|
|
'test-session',
|
|
api_id,
|
|
api_hash,
|
|
device_model='Desktop (Ubuntu)',
|
|
system_version='Ubuntu 22.04',
|
|
app_version='1.0.0',
|
|
lang_code='ru',
|
|
system_lang_code='ru'
|
|
)
|
|
|
|
await client.connect()
|
|
|
|
try:
|
|
# Check if already authorized
|
|
if await client.is_user_authorized():
|
|
print("Already authorized!")
|
|
me = await client.get_me()
|
|
print(f"Logged in as: {me.first_name} @{me.username}")
|
|
return
|
|
|
|
# Try to send code
|
|
print(f"Requesting code for {phone}...")
|
|
result = await client.send_code_request(phone)
|
|
print(f"Code sent! Type: {result.type}")
|
|
print(f"Phone code hash: {result.phone_code_hash}")
|
|
|
|
# Wait for user input
|
|
code = input("Enter the code: ")
|
|
|
|
try:
|
|
await client.sign_in(phone, code, phone_code_hash=result.phone_code_hash)
|
|
except SessionPasswordNeededError:
|
|
print("2FA enabled! Enter your cloud password:")
|
|
password = input("Password: ")
|
|
await client.sign_in(password=password)
|
|
|
|
me = await client.get_me()
|
|
print(f"Successfully logged in as: {me.first_name} @{me.username}")
|
|
|
|
except FloodWaitError as e:
|
|
print(f"FLOOD WAIT! Must wait {e.seconds} seconds ({e.seconds // 60} minutes)")
|
|
print(f"Try again after {e.seconds} seconds")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
finally:
|
|
await client.disconnect()
|
|
|
|
asyncio.run(main())
|