BlackElefant
BlackElefant

Reputation: 37

GSpread exception: 'expected_headers' are not uniques' on different machine

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.

Upvotes: 1

Views: 3108

Answers (2)

deepanshMathur
deepanshMathur

Reputation: 81

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

Upvotes: 1

BlackElefant
BlackElefant

Reputation: 37

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

Upvotes: 1

Related Questions