Python 将telethon与django一起使用:线程'中没有当前事件循环;螺纹-1';
我想使用来自django的Telethon。但当我运行它时,我会得到以下错误: RuntimeError:线程“thread-1”中没有当前事件循环 我的代码视图。py: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
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)
我可以帮忙。你能找到解决办法吗?我可以帮忙。你能找到解决办法吗?