@perfect_fsb

Почему вылезает эта ошибка?

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


вот мой код:
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)
  • Вопрос задан
  • 2897 просмотров
Решения вопроса 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Python
Седой и строгий
Из документации:
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.

То есть что-то в вашем коде пытается использовать asyncio в потоках. Подозреваю, что вы нам не полный код показали.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы