我真的不明白元组是如何工作的。但我所知道的是它们看起来像这样。
(1, variable)
但我不断收到错误:
Python type tuple cannot be converted
有人可以帮忙吗这是我的代码:
@client.command()
async def buy(ctx, item: str):
USER_ID = ctx.message.author.id
write_log("Buy command requested")
#write_log("Sending GET request to Cosmos API...")
try:
SQL.execute("SELECT price FROM shop WHERE itemname = %s", (item,))
price = SQL.fetchone()
SQL.execute("SELECT balance FROM Accounts WHERE user_id = %s", (USER_ID,))
SQL.execute("UPDATE Accounts SET balance = balance - %s WHERE user_id = %s", (price, USER_ID))
db.commit()
await ctx.send(f"Successfully bought **{item}** for **{price} Rollars**.")
except Exception as ex:
write_log('ERROR')
full_traceback = traceback.format_exc()
write_log(f'Errored whilst sending ctx(embed), (about): {ex} {full_traceback}')
完整的回溯:
Traceback (most recent call last):
File "Bot.py", line 316, in buy
SQL.execute("UPDATE Accounts SET balance = balance - %s WHERE user_id = %s", (price, USER_ID))
File "/home/vihanga/lib/python3.8/site-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "/home/vihanga/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 626, in prepare_for_mysql
result = self._cmysql.convert_to_mysql(*params)
_mysql_connector.MySQLInterfaceError: Python type tuple cannot be converted
如果您能向我解释它是如何工作的并可能帮助我解决错误,我将不胜感激。
慕后森
相关分类