что означает эта ошибка и как его исправить
[2023-06-04 17:25:16,740] ERROR in app: Exception on /connect_acc [GET]
Traceback (most recent call last):
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/main/app.py", line 112, in connect_account
user_bot = new_bot(name, phone_number, code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/main/app.py", line 39, in new_bot
asd = Client(
^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/pyrogram/client.py", line 267, in __init__
self.dispatcher = Dispatcher(self)
^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/pyrogram/dispatcher.py", line 58, in __init__
self.loop = asyncio.get_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/asyncio/events.py", line 677, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-2 (process_request_thread)'.
Вот код
import threading
import asyncio
from flask import Flask, request, render_template, url_for, redirect
from flask_sqlalchemy import SQLAlchemy
from pyrogram import Client, filters
from pyrogram import idle
from pyrogram.errors import RPCError
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///acc.db'
db = SQLAlchemy(app)
the_bot = Client('bot',
1234567890,
'qwertyiop[asdfghjklcxvbnm,')
class Accounts(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False )
tel = db.Column(db.String(100), nullable=False )
listener = db.Column(db.Integer, nullable=False )
forwarder = db.Column(db.Integer, nullable=False )
def __repr__(self):
return f"<Accounts {self.id}>"
API_ID = 12345678890
API_HASH = 'йцукенгшщзхфывапролд'
phone_hash = None
def new_bot(name, phone_number, code):
asd = Client(
name = name,
phone_number=phone_number,
api_id=API_ID,
api_hash=API_HASH,
)
try:
asd.connect()
asd.sign_in(phone_number=phone_number, phone_code=code, phone_code_hash=phone_hash)
except RPCError as e:
print(e)
finally:
asd.disconnect()
return asd
bots = []
@app.route('/app/accounts', methods=['POST', 'GET'])
def accounts_page():
global phone_hash
if request.method == "POST":
phone_number = request.form['phone']
name = request.form['name']
account = Accounts(name=name, tel=phone_number, listener=0, forwarder=0)
try:
db.session.add(account)
db.session.commit()
the_bot.connect()
hs = the_bot.send_code(phone_number)
phone_hash = hs.phone_code_hash
the_bot.disconnect()
print(phone_hash)
return "Success"
except:
return "При создании аккаунта произошла ошибка"
else:
list_of_accounts = Accounts.query.all()
if len(list_of_accounts) == 0:
list_of_accounts = ""
else:
list_of_accounts = Accounts.query.all()
return render_template('app/accounts.html', list_of_accounts=list_of_accounts)
@app.route('/del', methods=['GET'])
def accounts_delete():
index = request.args.get('index')
row = db.session.query(Accounts).filter(Accounts.id == index).first()
if row is None:
return "Error"
db.session.delete(row)
db.session.commit()
return redirect('/app/accounts')
@app.route('/connect_acc', methods=['GET'])
def connect_account():
code = request.args.get('the_code')
code_name = request.args.get('code_name')
code_tel = request.args.get('code_tel')
phone_number = '+998915243845'
name = code_name
if not phone_number.startswith('+'):
raise ValueError('Invalid phone number entered!')
user_bot = new_bot(name, phone_number, code)
bots.append(user_bot)
return f"{code}<br>{code_name}<br>{code_tel}<br>"
def app_run():
app.run()
#? def pyro_run():
# for bot in bots:
# bot.start()
# @bot.on_message(filters.me)
# def start(client, message):
# message.reply('Hello, World!')
# idle()
# for bot in bots:
# ? bot.stop()
if __name__ == "__main__":
for bot in bots:
bot.start()
@bot.on_message(filters.me)
def start(client, message):
message.reply('Hello, World!')
app_thread = threading.Thread(target=app_run, daemon=True)
app_thread.start()
idle()
for bot in bots:
bot.stop()
Помогите пожалуйста, запускал
flask и
pyrogram в одном файле с помошью потоков.