aiomysql
aiomysql copied to clipboard
Error raised when creating a cursor when cursorclass is set in connection
Traceback (most recent call last):
File "c:\Users\mail\Dropbox\Développement\AYB Verification bot\cogs\developer.py", line 80, in _eval
result = await codefunc()
File "<string>", line 3, in evalcode
File "c:\Users\mail\Dropbox\Développement\AYB Verification bot\dbmanagement.py", line 40, in get_bot
r = await query("SELECT * FROM bots WHERE client_id = %s", botID)
File "c:\Users\mail\Dropbox\Développement\AYB Verification bot\dbmanagement.py", line 27, in query
async with db.cursor() as cur:
File "C:\Users\mail\AppData\Roaming\Python\Python37\site-packages\aiomysql\connection.py", line 417, in cursor
cur = self.cursorclass(self, self._echo)
TypeError: __init__() takes 2 positional arguments but 3 were given
DB functions:
import aiomysql
import pymysql
db = None
async def connect():
c = await aiomysql.connect(
host="HOST",
user="USER",
password="PASS",
db="DB_NAME",
autocommit=True,
cursorclass=pymysql.cursors.DictCursor
)
return c
async def query(sql, *args):
global db
if not db:
db = await connect()
else:
await db.ping(reconnect=True)
async with db.cursor() as cur:
await cur.execute(sql, args)
print("========")
print("SQL: " + str(sql))
print("Description: " + str(cur.description))
r = await cur.fetchall()
print("Fetchall: " + str(r))
print("========")
return r
Found what's wrong, you need to provide aiomysql cursor type. Documentation is wrong here then: