Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将telethon与django一起使用:线程'中没有当前事件循环;螺纹-1';_Python_Django_Multithreading_Asynchronous_Telethon - Fatal编程技术网

Python 将telethon与django一起使用:线程'中没有当前事件循环;螺纹-1';

Python 将telethon与django一起使用:线程'中没有当前事件循环;螺纹-1';,python,django,multithreading,asynchronous,telethon,Python,Django,Multithreading,Asynchronous,Telethon,我想使用来自django的Telethon。但当我运行它时,我会得到以下错误: RuntimeError:线程“thread-1”中没有当前事件循环 我的代码视图。py: from django.shortcuts import render,HttpResponse from telethon.sync import TelegramClient, events async def join(client): ch = '@andeh_ir' try: awa

我想使用来自django的Telethon。但当我运行它时,我会得到以下错误:

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

我的代码视图。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')
我的解决方案 #导入异步

 import asyncio
 api_id = xxxx
 api_hash = 'b772662cf8a918bfbc39ee2aee36f6cc'
 loop = asyncio.new_event_loop()
 asyncio.set_event_loop(loop)
 client = TelegramClient(phone, api_id, api_hash, loop=loop)
我的解决方案 #导入异步

 import asyncio
 api_id = xxxx
 api_hash = 'b772662cf8a918bfbc39ee2aee36f6cc'
 loop = asyncio.new_event_loop()
 asyncio.set_event_loop(loop)
 client = TelegramClient(phone, api_id, api_hash, loop=loop)

我可以帮忙。你能找到解决办法吗?我可以帮忙。你能找到解决办法吗?