Python Forum
help RuntimeError: no running event loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help RuntimeError: no running event loop
#1
from dataclasses import dataclass
from tkinter.messagebox import YES
from telethon import TelegramClient
from telethon import utils
from telethon.errors.rpcerrorlist import PhoneNumberBannedError
import csv
import configparser
from telethon.sync import TelegramClient
from rich.console import Console
from rich.text import Text
from rich.theme import Theme
from rich.traceback import install
from asyncio import create_task, gather
import os, asyncio
konsol = Console()
secenek = int(konsol.input(f"[yellow4][!] - Lütfen Bir Seçenek Giriniz :"))
def bankontrol():
    config = configparser.ConfigParser()
    config.read("ayarlar.ini")
    api_id = (config['Redstone']['API_ID']).strip()
    api_hash = (config['Redstone']['API_HASH']).strip()
    redstonebanned = []
    with open('numaralar.csv','r',) as d:
        sl = 0
        tasks = (create_task([row[0] for row in csv.reader(d)]))
        for numaraR in gather(*tasks, return_exceptions=True):
            numara = utils.parse_phone(numaraR)    
            sl += 1
            konsol.print(f"""[bold yellow4][↓] Kontrol Edilen Numara [↓][/]
        [bold magenta]{numara}""")
            client = TelegramClient(f"sessions/{numara}", api_id, api_hash)
            client.connect()
            if client.is_user_authorized():
                konsol.print("""[bold green][✓] Tebrikler, Bu numara Temiz! [✓]""")
            if not client.is_user_authorized():
                try:
                    konsol.print("""[bold red][×] Üzgünüm, Bu numara Banlı! [×]
                    """)
                    redstoneban = utils.parse_phone(numaraR)
                    redstonebanned.append(redstoneban)
                    continue
                except:
                    print('Ban')
                    rexhacks = str(sl)
                    redstoneban = utils.parse_phone(numaraR)
                    redstonebanned.append(redstoneban)
                    continue
            print()
    
        done = True
        konsol.print(f"[bold blue][!] Toplam {len(redstonebanned)} Adet Numara BanlıNumaralar.csv'ye Kayıt Edildi.")
        input()
if secenek == 1:
    bankontrol()
Error:
loop = events.get_running_loop() RuntimeError: no running event loop
Reply
#2
There is no "loop = events.get_running_loop()" in your example. Please include the complete error trace.
Reply
#3
(Oct-18-2022, 07:47 PM)deanhystad Wrote: There is no "loop = events.get_running_loop()" in your example. Please include the complete error trace.

I didn't use it but it gives error like this
Reply
#4
(Oct-18-2022, 07:47 PM)deanhystad Wrote: There is no "loop = events.get_running_loop()" in your example. Please include the complete error trace.
if secenek==2:    
    async def bankontrol():
        config = configparser.ConfigParser()
        config.read("ayarlar.ini")
        api_id = (config['Redstone']['API_ID']).strip()
        api_hash = (config['Redstone']['API_HASH']).strip()
        redstonebanned = []
        with open('numaralar.csv','r',) as d:
            sl = 0
            tasks = (asyncio.create_task([row[0] for row in csv.reader(d)]))
            for numaraR in asyncio.gather (*tasks, return_exceptions=True):
                sl += 1
                numara = utils.parse_phone(numaraR)

                konsol.print(f"""[bold yellow4][↓] Kontrol Edilen Numara [↓][/]
            [bold magenta]{numara}""")
                client = TelegramClient(f"sessions/{numara}", api_id, api_hash)
                client.connect()
                if client.is_user_authorized():
                    konsol.print("""[bold green][✓] Tebrikler, Bu numara Temiz! [✓]""")
                if not client.is_user_authorized():
                    try:
                        konsol.print("""[bold red][×] Üzgünüm, Bu numara Banlı! [×]
                        """)
                        redstoneban = utils.parse_phone(numaraR)
                        redstonebanned.append(redstoneban)
                        continue
                    except:
                        print('Ban')
                        rexhacks = str(sl)
                        redstoneban = utils.parse_phone(numaraR)
                        redstonebanned.append(redstoneban)
                        continue
                print()
        
            done = True
            konsol.print(f"[bold blue][!] Toplam {len(redstonebanned)} Adet Numara BanlıNumaralar.csv'ye Kayıt Edildi.")
            input()
    asyncio.run(bankontrol())


i changed the codes like this and this error is gone but

Error:
File "C:\Users\sence\Desktop\telegrammmke\main.py", line 51, in bankontrol tasks = (asyncio.create_task([row[0] for row in csv.reader(d)])) File "C:\Users\sence\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 337, in create_task task = loop.create_task(coro) File "C:\Users\sence\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 438, in create_task task = tasks.Task(coro, loop=self, name=name) TypeError: a coroutine was expected, got ['905314721936', '905340522097', '905342659476']
I came across something like this ['905314721936', '905340522097', '905342659476'] these are the lines it should read in numaralar.csv
Reply
#5
What is this supposed to do?
tasks = (asyncio.create_task([row[0] for row in csv.reader(d)]))
According to the documentation, the first argument to asyncio.create_task() is the coroutine.

Are you trying to do something like this where the csv reader provides arguments for the coroutine?
import asyncio

# Emulate (very loosely) a csv reader
csvReader = [[i] for i in range(1, 10)]

async def coroutine(value=3):
    await asyncio.sleep(1)
    return value**2


async def main():
    tasks = (asyncio.create_task(coroutine(row[0])) for row in csvReader)
    results = await asyncio.gather(*tasks, return_exceptions=True)
    print(results)

asyncio.run(main())
Reply
#6
Quote:What is this supposed to do?

Making numbers.csv read the numbers I type one after the other
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A question about 'Event loop is closed' fc5igm 2 2,232 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  bleak library RuntimeError: This event loop is already running alice93 3 4,117 Sep-30-2021, 08:06 AM
Last Post: alice93
  loop running indefinitely shantanu97 6 2,601 Sep-29-2021, 08:03 PM
Last Post: deanhystad
  Running A Loop Until You See A Particular Result knight2000 6 31,727 Sep-04-2021, 08:55 AM
Last Post: knight2000
  Running loop at specific frequency mdsousa 3 5,961 Apr-21-2021, 11:22 AM
Last Post: jefsummers
  RuntimeError: generator raised StopIteration quest 1 5,825 Mar-28-2021, 08:11 PM
Last Post: quest
  RuntimeError: This event loop is already running newbie2019 2 6,964 Sep-30-2020, 06:59 PM
Last Post: forest44
  RuntimeError: Optimal parameters not found: Number of calls to function has reached m bntayfur 0 6,159 Aug-05-2020, 04:41 PM
Last Post: bntayfur
  Running function from parent module which has a loop in it. ta2909i 1 2,698 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  RuntimeError: can't open file Hadad 2 5,365 Aug-27-2019, 04:23 PM
Last Post: Hadad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020