Функции Telethon send_request_code и Sign_in не отправляютсяPython

Программы на Python
Anonymous
Функции Telethon send_request_code и Sign_in не отправляются

Сообщение Anonymous »

У меня есть код обработчика в моем боте Telegram.
Бот написан на айограмме.

Код: Выделить всё

async def login_and_save_session(session_name, phone_number, call: types.CallbackQuery, state: FSMContext):
try:
await state.update_data(session_file_path=my_files.get_session_file_path(session_name))
session_file_path = await get_session_file_path_for_session(state=state)
client = TelegramClient(session_file_path, config.api_id, config.api_hash)
await client.connect()
if await client.is_user_authorized():

if not await client.is_user_authorized():
try:
await client.sign_in(phone=str(phone_number))
await handle_request_code(call, state)
while await get_add_session_flag(state):
await asyncio.sleep(3)
code = await get_code_for_session(state)
await client.sign_in(phone=str(phone_number), code=str(code))
except SessionPasswordNeededError:
await handle_request_2fa_password(call, state)
while await get_add_session_flag(state):
await asyncio.sleep(3)
password = await get_2fa_password_for_session(state)
await client.sign_in(password=str(password))
except Exception as e:
if client:
await client.disconnect()
if session_file_path and os.path.exists(session_file_path):
my_files.delete_file(session_file_path)
Из логов мы видим, что ошибка возникает при попытке отправить код или авторизоваться здесь.

Код: Выделить всё

        if not await client.is_user_authorized():
try:
await client.sign_in(phone=str(phone_number))
await handle_request_code(call, state)
while await get_add_session_flag(state):
await asyncio.sleep(3)
code = await get_code_for_session(state)
await client.sign_in(phone=str(phone_number), code=str(code))
except SessionPasswordNeededError:
await handle_request_2fa_password(call, state)
while await get_add_session_flag(state):
await asyncio.sleep(3)
password = await get_2fa_password_for_session(state)
await client.sign_in(password=str(password))
except Exception as e:
if client:
await client.disconnect()
if session_file_path and os.path.exists(session_file_path):
my_files.delete_file(session_file_path)
Я уверен, что формат данных правильный, но вылезает ошибка **bytes or str, а не **
Упростил функцию и всё заработало.

Код: Выделить всё

async def send_code(phone_number):
client = TelegramClient(StringSession(), api_id, api_hash)

await client.connect()

if not await client.is_user_authorized():
await client.send_code_request(phone_number)
else:

await client.disconnect()

asyncio.run(send_code(phone_number))
Но я не могу сделать авторизацию внутри бота, как я уже говорил выше.

Подробнее здесь: https://stackoverflow.com/questions/781 ... e-not-sent

Вернуться в «Python»