GSPREAD异常:' endiss_headers'不是唯一的'在不同的机器上
我有以下代码设置:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 @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
对我来说,问题是在特定的Google表中,我的两个列名称完全相同。
For me, the issue was that in a specific google sheet, two of my column names were exactly identical.