使用以下查询时出现以下错误,我在执行 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/