gpt4 book ai didi

python - 如何修复 ValueError : need more than 1 value to unpack?

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:26 26 4
gpt4 key购买 nike

使用以下查询时出现以下错误,我在执行 cursor.fetchall 时已经给出了变量,不确定为什么会出现此错误,如何解决?

查询:-

query = """SELECT metabuild,testbed FROM gerrits.pw WHERE warehouse ='%s'"""%(warehouse_name)
rows = cursor.execute(query)
(metaBuild,testbed)= cursor.fetchall()

错误:-

    (metaBuild,testbed)= cursor.fetchall()
ValueError: need more than 1 value to unpack

最佳答案

fetchall 返回一个元组列表,每行一个元组。如果您确定您的查询只返回一行,请执行

(metaBuild,testbed)= cursor.fetchall()[0]

关于python - 如何修复 ValueError : need more than 1 value to unpack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31466641/

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