Parameters error: ValueError: 'params' arg (<class 'list'>) can be only a tuple or a dictionary

Parameters error: ValueError: 'params' arg (<class 'list'>) can be only a tuple or a dictionary

我正在尝试将一些 discord 机器人数据插入数据库。我做了参数方法,但它不起作用。我刚接触 MYSQL 和 python。

我的代码

@bot.event
#Edit Log
async def on_message_edit(before, after):
    MemberId = before.author.id
    await bot.send_message(bot.get_channel('480526097331650590'), 'The user <@%s> have edited his message from ``' % (MemberId) + before.content + '`` to `` ' + after.content + ' `` ')


    #Connection to sql
    conn = pymssql.connect(server='HAMOOOOD25\DISCORDPY', user='sa', password='31045', database='ChatLogs')
    cursor = conn.cursor()

    #Declaring vars
    BeforeId = before.id
    BAuthId = before.author.id
    BAuthN = before.author.id
    Befcon = before.content
    Aftcon = after.content

    sql = "INSERT INTO Editedmsg VALUES (Message_ID, Message_Author_ID, Message_Owner_Name, Previous_Message, After_Message)"
    cursor.execute(sql, [(before.id), (before.author.id,), (before.author.id), (before.content), (after.content)])
    conn.close()

我的错误

ValueError: 'params' arg (<class 'list'>) can be only a tuple or a dictionary.

显然,错误消息建议您使用 tuple 而不是 list 在您的 cursor.execute call. Besides that, your sql query is not properly formed (see examples 部分)。您的 execute 调用应该如下所示:

sql = "INSERT INTO Editedmsg VALUES (%d, %d, %d, %s, %s)"
params = (before.id, before.author.id, before.author.id, 
          before.content, after.content)
cursor.execute(sql, params)