Код: Выделить всё
terminate_signal_received = False
async def main():
global terminate_signal_received
client = TelegramClient(session_name, appid, apihash)
print(f'Registering events on {input_channels_entities}...')
@client.on(events.NewMessage(chats=input_channels_entities))
async def handler(event):
msg = event.message.message
await send_to_webhook(msg, event.chat.title)
# Start the client and run until interrupted or an exception occurs
try:
await client.start()
print("Establishing test message...")
await client.send_message(log_tg_channel, f"✅ **{name}** is online!")
print("Client started!")
# Run until termination signal is received or an exception occurs
while not terminate_signal_received:
await asyncio.sleep(0.1)
except asyncio.CancelledError:
print("Cancelled!")
except Exception as e:
print(f"Error: {e}")
finally:
print("Logging about termination...")
if client.is_connected():
await client.send_message(log_tg_channel, f"⛔️ **{name}** was terminated!")
await client.disconnect()
else:
print("Can't! Client is not connected!")
# Signal handler for termination signals
def signal_handler(sig, frame):
global terminate_signal_received
print(f"Received signal {sig}! Stopping...")
terminate_signal_received = True
# Register the signal handler
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
if __name__ == '__main__':
asyncio.run(main())
Код: Выделить всё
INFO:telethon.client.updates:Cannot get difference since the account is not logged in: AuthKeyUnregisteredError
Код: Выделить всё
telethon.errors.rpcerrorlist.AuthKeyUnregisteredError: The key is not registered in the system (caused by SendMessageRequest)
Очень запутанно, и я застрял на этом уже 2 недели без какого-либо прогресса, поэтому, пожалуйста, помогите...
Кстати, сегодня, после нескольких дней перерыва, скрипт действительно работает в моей тестовой среде в течение получаса и был успешно завершен после это. Но после этого он отказывается работать как в тестовой среде, так и на сервере.
Подробнее здесь: https://stackoverflow.com/questions/766 ... -logged-in
Мобильная версия