V
V
venera0602020-12-21 19:56:01
MySQL
venera060, 2020-12-21 19:56:01

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()


Requests to the database:
1 request works correctly and 2 crashes

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()


If you put * in the 2nd request or specify only 1 line instead of several, it gives the same error
5fe0d318510d3301143456.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-12-21
@venera060

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 question

Ask a Question

731 491 924 answers to any question