P
P
perfect_fsb2020-08-13 02:43:01
Python
perfect_fsb, 2020-08-13 02:43:01

Why does this error pop up?

RuntimeError: There is no current event loop in thread 'WorkerThread1'.


here is my code:
import telebot, sqlite3, requests, time
from telebot import types
from datetime import datetime
# -*- coding: utf-8 -*-
from telethon import TelegramClient, events, sync
from telethon.tl.types import InputPhoneContact
from telethon import functions, types
import random, string

client = TelegramClient()
client.connect()
if not client.is_user_authorized():
    client.send_code_request('')
    client.sign_in('+1214', input('Enter code: '))

TOKEN = 
bot = telebot.TeleBot(TOKEN)

def sex(message):
    num = message.text
    randoma = random.choice(string.ascii_letters)
    randomb = random.choice(string.ascii_letters)
    contact = InputPhoneContact(client_id = 0, phone = num, first_name=randoma, last_name=randomb)
    contacts = client(functions.contacts.ImportContactsRequest([contact]))
    username = contacts.to_dict()['users'][0]['username']
    bot.send_message(message.chat.id, f'@{username}')

@bot.message_handler(content_types=['text'])
def referer(message):
        a = bot.send_message(message.chat.id, '''отправь мне номер: ''')
        bot.register_next_step_handler(a, sex)

while True:
    try:
        bot.infinity_polling(interval=0)
    except:
        bot.infinity_polling(interval=0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-08-13
@perfect_fsb

From documentation :

The default policy defines context as the current thread, and manages
an event loop per thread that interacts with asyncio. If the current
thread doesn't already have an event loop associated with it, the
default policy's get_event_loop() method creates one when called from
the main thread, but raises RuntimeError otherwise.

That is, something in your code is trying to use asyncio on threads. I suspect that you did not show us the full code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question