【发布时间】:2022-08-22 17:30:10
【问题描述】:
我设置了以下代码:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
scope = [
\'https://www.googleapis.com/auth/spreadsheets\',
\'https://www.googleapis.com/auth/drive\'
]
credentials=ServiceAccountCredentials.from_json_keyfile_name(\'keyfile.json\',scope)
gc= gspread.authorize(credentials)
sh= gc.open(\'Spreadsheet\')
worksheet = sh.worksheet(sheetName)
dataframe = pd.DataFrame(worksheet.get_all_values())
奇怪的是,这段代码在我的 Macbook 上运行良好。 但是,如果我的同事在他的 Macbook 上执行它,他会得到这个异常:
\'GSpreadException: the given \'expected_headers\' are not uniques\' 错误
=> 我试图追踪问题,似乎 get_all_values 无法正确加载电子表格内容,因此所有列标题都被认为是相同的。电子表格的相关表格当然有实际内容。
奇怪的是它可以在一台机器上工作,但不能在另一台机器上工作,这让我相信这可能是一个版本问题。
-
我不得不为我糟糕的英语水平道歉。不幸的是,根据您的问题,我无法理解
the spreadsheet contents cannot be correctly loaded by get_all_values。我可以使用示例输入电子表格作为图像和示例输出值向您询问它的详细信息吗?关于样本输出,您能否也提供您的期望值? -
您是否检查过您是否使用相同版本的
gspread?最近添加了这个例外。