Answer the question
In order to leave comments, you need to log in
System error: 10038 An attempt was made to perform an operation on an object that is not a socket. How to decide?
main function for selecting question and answers:
def game(n):
db_work = mySQL()
rq = db_work.select_q(n) #строка с вопросом
ra = db_work.select_a(n) #строки с ответами
marcup = utils.answers_marcup(ra) #заполнение клавиатуры ответами
bot.send_message(user_id, rq[1], reply_markup=marcup)
db_work.close()
def __init__(self):
self.connection = mysql.connector.connect(host="localhost", user="root", passwd="123", db="test_db")
self.cursor = self.connection.cursor()
def select_q(self, id):
with self.connection:
self.cursor.execute('SELECT * FROM questions WHERE id = ' + str(id))
return self.cursor.fetchone()
def select_a(self, id_q):
with self.connection:
self.cursor.execute('SELECT answer FROM answers WHERE id_q = ' + str(id_q))
return self.cursor.fetchall()
Answer the question
In order to leave comments, you need to log in
You don't understand how with works? The call to select_q closes self.connection. An attempt in select_a to read from a closed connection results in an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question