MySQL和Python编程错误:1064(42000)

时间:2019-08-12 15:59:32

标签: python mysql discord.py-rewrite

Ignoring exception in command imageshow:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "/Users/user/bot.py", line 318, in image
    mycursor.execute(get_name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/cursor.py", line 551, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection.py", line 490, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name = 'testname'' at line 1

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

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
    await ctx.command.invoke(ctx)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/discord/ext/commands/core.py", line 728, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/discord/ext/commands/core.py", line 88, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to 
use near 'name = 'testname'' at line 1

当我尝试从MySQL数据库中选择数据时(也使用Discord.py),出现了此错误。这是SQL:

@bot.command()
async def imageshow(ctx, name2):
    get_image = "SELECT image FROM name_list WHERE name = '{0}'".format(name2)
    mycursor.execute(get_image)
    image_url = mycursor.fetchone()

    get_name = "SELECT display_name FROM name_list WHERE name = '{0}'".format(name2)
    mycursor.execute(get_name)
    name = mycursor.fetchone()

    for image in image_url:
        final_image = image

    for display_name in name:
        final_name = display_name

    embed = discord.Embed(title="{0}".format(final_name), description="{0}'s Image".format(final_name), color=0xeee657)

    embed.set_image(url="{0}".format(final_image))

    await ctx.send(embed=embed)

name_list表存在,image列存在,name列存在。为什么我会收到此错误?我添加了完整的代码以更好地理解我的代码。这在我的其他命令之一中起作用,为什么不在这里?

1 个答案:

答案 0 :(得分:0)

完成。在执行此命令之前,我遇到一个冲突,是什么导致此错误。已修正!