Answer the question
In order to leave comments, you need to log in
Why does await con.commit() throw a ValueError?
I use Aiomysql in conjunction with Aiogram. Experimentally, I found out that the await con.commit () line causes the error given at the end. But why?
async def __query(self, *args, **kwargs):
con = await aiomysql.connect(
host=self.__db_host,
user=self.__db_login,
password=self.__db_pass,
db=self.__db_name,
)
cur = await con.cursor()
await cur.execute(*args, **kwargs)
res = await cur.fetchall()
await con.commit()
await cur.close()
Traceback (most recent call last):
File "/home/iindin/.local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
GeneratorExit
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/iindin/.local/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 273, in process_update
return await self.callback_query_handlers.notify(update.callback_query)
File "/home/iindin/.local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 127, in notify
current_handler.reset(ctx_token)
ValueError: <Token var=<ContextVar name='current_handler' at 0x7f7ab7a7df90> at 0x7f7ab5caa800> was created in a different Context
Exception ignored in: <coroutine object Handler.notify at 0x7f7ab5c42140>
Traceback (most recent call last):
File "/home/iindin/.local/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 127, in notify
current_handler.reset(ctx_token)
ValueError: <Token var=<ContextVar name='current_handler' at 0x7f7ab7a7df90> at 0x7f7ab5c7bc40> was created in a different Context
return res
Answer the question
In order to leave comments, you need to log in
Look at the basic example , maybe it's better to remake it in its image and likeness?
pool = await aiomysql.create_pool(host='127.0.0.1', port=3306,
user='root', password='',
db='mysql', loop=loop)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT 42;")
print(cur.description)
(r,) = await cur.fetchone()
assert r == 42
pool.close()
await pool.wait_closed()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question