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

标签 python database

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

相关文章:

python - 在Google CoLab Notebook中,如何在不进行两次身份验证的情况下从公共(public)Google云端硬盘和我的个人硬盘读取数据?

Python:写入文件失败且没有错误 - 导致空文件

python - 操作错误(2003、 "Can' t 连接到 '127.3.138.130' (111) 上的 MySQL 服务器")

mysql - 如何将表1字段的数据插入表2字段

database - Django 。南。英雄联盟。 key 错误 : 'default'

python - 如何在 Python 中使用带有条件的 Groupby

python - 如果我的模式来自另一个字符串,如何用 regex() 指示原始字符串?

mysql - 使用仅包含外键的单个表查询从 3 个表获取数据

c# - 如何在不将第一个实体插入 Entity Framework C# 中的数据库的情况下将实体 ID 分配给另一个实体?

database - JPA + Spring 如何用自定义表和数据初始化数据库