GSPREAD异常:' endiss_headers'不是唯一的'在不同的机器上

发布于 2025-02-04 11:12:52 字数 796 浏览 2 评论 0原文

我有以下代码设置:

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' error

我试图追踪问题,看来电子表格内容不能由get_all_values正确加载,因此所有列标头都被认为是相同的。电子表格的杂音表肯定具有实际内容。

奇怪的是,它可以在一台机器上工作,但不能在另一台计算机上使用,这使我相信这可能是一个版本的问题。

I have the following code set up:

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())

The strange thing is, this code is working fine on my Macbook.
However, if my colleague executes it on his Macbook, he gets this Exception:

'GSpreadException: the given 'expected_headers' are not uniques' error

I tried to trace the issue and it appears that the spreadsheet contents cannot be correctly loaded by get_all_values and therefore all column headers are perceived the same. The assoicated sheet of the spreadsheet certainly has actual content.

It is strange that it works on one machine but not on another, which makes me believe it may be a versioning issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗酒趁年少 2025-02-11 11:12:52

正如 @lavigne958指出的,问题的确是Gspread的版本
降级到较早版本的Gspread解决了问题

The issue was indeed the version of gspread, as pointed out by @Lavigne958
Downgrading to an earlier version of gspread solved the issue

带刺的爱情 2025-02-11 11:12:52

对我来说,问题是在特定的Google表中,我的两个列名称完全相同。

For me, the issue was that in a specific google sheet, two of my column names were exactly identical.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文