小编Sas*_*deH的帖子

将 telethon 与 django 结合使用:线程“Thread-1”中没有当前事件循环

我想使用django中的Telethon。但是当我运行它时,我收到以下错误:

RuntimeError:线程“Thread-1”中没有当前事件循环。

我的代码views.py:

from django.shortcuts import render,HttpResponse
from telethon.sync import TelegramClient, events

async def join(client):
    ch = '@andeh_ir'
    try:
        await client(JoinChannelRequest(ch))
        print('[+] Joined The Channel')
    except:
        print('[-] skiped')

def addChannel(request):
    api_id   =   XXXXXX
    api_hash = 'xxxxxxxxxxxxxxxxxxxxx'
    client = TelegramClient('+254716550762', api_id, api_hash )
    with client:
        client.loop.run_until_complete(join(client))
    return HttpResponse('addChannel')
Run Code Online (Sandbox Code Playgroud)

python django multithreading asynchronous telethon

2
推荐指数
1
解决办法
3205
查看次数

标签 统计

asynchronous ×1

django ×1

multithreading ×1

python ×1

telethon ×1