B
B
bluefasik2022-01-14 13:51:30
MySQL
bluefasik, 2022-01-14 13:51:30

How to fix a lost connection error to MySQL?

I have a bot connected to mysql database. When you enter the /start command, it gives an error

mysql.connector.errors.OperationalError: 2055 Lost connection to MySQL server at '' , system error: 9 Bad file descriptor

When you enter the start command, a check is made for the presence of the user in the database.
bot.py

if(not db.check_user(message.from_user.id)):
  db.add_user(message.from_user.id, message.from_user.username)
  bot.send_message(message.chat.id, "<b>Добро пожаловать, </b>"+usname, reply_markup=keyboard, parse_mode="HTML", disable_web_page_preview = True)
else:
  bot.send_message(message.chat.id, "<b>Добро пож&nbsp;алов&quot;ать, </b>"+usname, reply_markup=keyboard, parse_mode="HTML", disable_web_page_preview = True)

sqlighter.py

def add_user(self, user_id, username):
  sql = "INSERT INTO `usersdb` (`user_id`, `username`) VALUES (%s,%s)"
  val = user_id, username
  self.user_cursor.execute(sql, val)
  self.user_mydb.commit()
  self.user_mydb.close()

def check_user(self, user_id):
  sql = "SELECT * FROM usersdb WHERE user_id = {0}".format(user_id)
  self.user_cursor.execute(sql)
  data = self.user_cursor.fetchone()
  return data

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-14
@bluefasik

self.user_mydb.close()
What do you think this call does?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question