I am trying to create an API that gets channels participants Telegram. I am using telethon API in python, I am getting this error
Runtime Error: There is no current event loop in thread
here is my code
import os from threading import Thread from flask import Flask, request from telethon import TelegramClient app = Flask(__name__) api_id = os.environ['API_ID'] api_hash = os.environ['API_HASH'] client = TelegramClient("anon", api_id, api_hash) async def follow(channel_name): # await client.connect() # await client(JoinChannelRequest(channel=channel_name)) me = await client.get_me() print(me.stringify()) channel_users = await client.get_participants(channel_name) return channel_users @app.route('/') def home(): return "I'm alive" @app.route("/follow_channel", methods=["POST"]) def follow_channel(): body = request.get_json() user_id = body["userId"] user_hash = body["userHash"] user_name = body["userName"] channel_name = body["channelName"] client.loop.run_until_complete(client.get_me()) return "helllo" def run(): app.run(host='0.0.0.0',port=8080) t = Thread(target=run) t.start()
asyncio-based libraries, I recommend you first learn to mix barebonesthreadingandasyncio. An easier route is to use an async alternative to Flask, such as Quart.