Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Using telethon with flask: There is no current event loop in thread 'Thread-1'. #1208

Description

@gekich

I want to use Telethon from the Flask Web App. But when I am running it, I am getting following error:

RuntimeError: There is no current event loop in thread 'Thread-1'.

Code that causes the issue

from flask import Flask
from telethon.sync import TelegramClient


app = Flask(__name__)

@app.route('/')
def index():
    api_id = XXXXXX
    api_hash = 'XXXXXXX'
    bot_token = 'XXXXXXX'
    client = TelegramClient('bot', api_id, api_hash)
    client.start()
    return 'Index Page'

if __name__ == '__main__':
    app.run()

I tried to fix the issue using sync-stale version of Telethon. But there are no type ChatBannedRights i need.
i used commands:
pip3 uninstall telethon
pip3 install --no-cache --upgrade git+https://github.com/LonamiWebs/Telethon@sync-stale
to install the sync-stale version.

And got error ImportError: cannot import name 'ChatBannedRights' from 'telethon.tl.types' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/telethon/tl/types/__init__.py) when tried to import type:

from telethon.tl.types import ChatBannedRights

So basically there are two issues:

  1. Im getting error "There is no current event loop in thread 'Thread-1'." while using Flask and Telethon
  2. There are no type ChatBannedRights in sync-stale version of Telethon.

Hope you can help me

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions