gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:42:25 39 4
gpt4 key购买 nike

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 列存在。为什么我会收到此错误?我添加了完整的代码以更好地理解我的代码。这在我的其他命令之一中有效,为什么在这里不行?

最佳答案

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

关于python - MySQL 和 Python 编程错误 : 1064 (42000),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57464516/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com