@EliteNoob

Как исправить ошибку?

Бот перестаёт выполнять команды, которые требуют подключения к MySQL, обычные команды выполняет. Подключение реализовано через mysql-connector и пул подключений. В чём может быть проблема?
код подключения
import mysql.connector
from bestconfig import Config
from mysql.connector import pooling
from mysql.connector import Error

config = Config() #config['version']

def getConnection(): 
    try:
        connection_pool = pooling.MySQLConnectionPool(pool_name="discord_pool",
                                                    pool_size=2,
                                                    pool_reset_session=True,
                                                    host=config['host'],
                                                    database=config['database'],
                                                    user=config['user'],
                                                    password=config['password'])

        # Get connection object from a pool
        connection_object = connection_pool.get_connection()

        if connection_object.is_connected():
            db_Info = connection_object.get_server_info()
            print("Connected to MySQL database using connection pool ... MySQL Server version on ", db_Info)

            cursor = connection_object.cursor()
            cursor.execute("select database();")
            record = cursor.fetchone()
            print("Your connected to - ", record)
        else:
            connection_object.reconnect(attempts=1, delay=0)

    except Error as e:
        print("Error while connecting to MySQL using Connection pool ", e)
    return connection_object


log
2022-12-25 05:52:00,155 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:09:37,816 ERROR Attempting a reconnect in 1.11s
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/discord/gateway.py", line 372, in from_client
    socket = await client.http.ws_connect(str(url))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/discord/http.py", line 536, in ws_connect
    return await self.__session.ws_connect(url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/client.py", line 779, in _ws_connect
    resp = await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1063, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 967, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
    return await fut
           ^^^^^^^^^
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/discord/client.py", line 624, in connect
    self.ws = await asyncio.wait_for(coro, timeout=60.0)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError
2022-12-25 07:09:39,518 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:27:23,366 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:44:19,708 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
  • Вопрос задан
  • 219 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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