Задать вопрос
MrShandy
@MrShandy
Python

Почему через время при запросе выдает ошибку 2013?

База данных: MySQL. Если сразу после запуска сделать запрос, то все нормально, но если сделать его спустя время будет ошибка:
Ошибка

Traceback (most recent call last):
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1802, in _execute_context
    self.dialect.do_execute(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\cursors.py", line 148, in execute
    result = self._query(query)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\cursors.py", line 310, in _query
    conn.query(q)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
    result.read()
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 692, in _read_packet
    packet_header = self._read_bytes(4)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 748, in _read_bytes
    raise err.OperationalError(
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\discord\ext\commands\core.py", line 220, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\reports.py", line 63, in report_member
    await self.create_report(ctx, "member", title, description, member, rule, proof)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\reports.py", line 106, in create_report
    if report.applicant_id == ctx.author.id and report.status == "Open":
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 481, in __get__
    return self.impl.get(state, dict_)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 941, in get
    value = self._fire_loader_callables(state, key, passive)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\attributes.py", line 972, in _fire_loader_callables
    return state._load_expired(state, passive)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\state.py", line 710, in _load_expired
    self.manager.expired_attribute_loader(self, toload, passive)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\loading.py", line 1451, in load_scalar_attributes
    result = load_on_ident(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\loading.py", line 407, in load_on_ident
    return load_on_pk_identity(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\loading.py", line 530, in load_on_pk_identity
    session.execute(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\orm\session.py", line 1692, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1614, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\sql\elements.py", line 325, in _execute_on_connection
    return connection._execute_clauseelement(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1481, in _execute_clauseelement
    ret = self._execute_context(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1845, in _execute_context
    self._handle_dbapi_exception(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 2026, in _handle_dbapi_exception
    util.raise_(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
    raise exception
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\base.py", line 1802, in _execute_context
    self.dialect.do_execute(
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\sqlalchemy\engine\default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\cursors.py", line 148, in execute
    result = self._query(query)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\cursors.py", line 310, in _query
    conn.query(q)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 548, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
    result.read()
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 1156, in read
    first_packet = self.connection._read_packet()
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 692, in _read_packet
    packet_header = self._read_bytes(4)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\pymysql\connections.py", line 748, in _read_bytes
    raise err.OperationalError(
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: SELECT reports.id AS reports_id, reports.status AS reports_status, reports.title AS reports_title, reports.description AS reports_description, reports.rule AS reports_rule, reports.proof AS reports_proof, reports.type AS reports_type, reports.channel_id AS reports_channel_id, reports.applicant_id AS reports_applicant_id, reports.respondent_id AS reports_respondent_id, reports.assigned_moderator_id AS reports_assigned_moderator_id, reports.current_moderator_id AS reports_current_moderator_id, reports.closed_moderator_id AS reports_closed_moderator_id, reports.creation_time AS reports_creation_time, reports.closing_time AS reports_closing_time 
FROM reports 
WHERE reports.id = %(pk_1)s]
[parameters: {'pk_1': 1}]
(Background on this error at: https://sqlalche.me/e/14/e3q8)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\discord\ext\commands\bot.py", line 1215, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\discord\ext\commands\core.py", line 1674, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\discord\ext\commands\core.py", line 998, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\MrSha\Documents\Projects\SG-bot\venv\lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query')
[SQL: SELECT reports.id AS reports_id, reports.status AS reports_status, reports.title AS reports_title, reports.description AS reports_description, reports.rule AS reports_rule, reports.proof AS reports_proof, reports.type AS reports_type, reports.channel_id AS reports_channel_id, reports.applicant_id AS reports_applicant_id, reports.respondent_id AS reports_respondent_id, reports.assigned_moderator_id AS reports_assigned_moderator_id, reports.current_moderator_id AS reports_current_moderator_id, reports.closed_moderator_id AS reports_closed_moderator_id, reports.creation_time AS reports_creation_time, reports.closing_time AS reports_closing_time 
FROM reports 
WHERE reports.id = %(pk_1)s]
[parameters: {'pk_1': 1}]
(Background on this error at: https://sqlalche.me/e/14/e3q8)


Может я как то не правильно работаю с сессиями?

Не знаю, нужно ли прилагать модели
  • Вопрос задан
  • 92 просмотра
Подписаться 1 Простой 9 комментариев
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы