How to fix 'tuple' object has no attribute 'open'?

162 views Asked by At

Im parsing data for study purposes so I create scraping module, data frame module and now I need to finish "upload to Google Drive data frame as Google Sheet" but stuck on this error.

from fileinput import filename
import gspread

credentials = {...
}
gc = gspread.oauth_from_dict(credentials)

tag = bs_search
sh = gc.open(filename, 'kid')
worksheet = sh.add_worksheet(title = tag, rows=100, cols=20)
worksheet.update([df.columns.values.tolist()] + df.values.tolist())
worksheet.update_cell(1, 4, 'Send to')
worksheet.update_cell(1, 5, 'Not Send to')
worksheet.update_cell(1, 6, 'Instagram')

Output:

   13 gc = gspread.oauth_from_dict(credentials)
     15 tag = bs_search
---> 16 sh = gc.open(filename, 'kid')
     17 worksheet = sh.add_worksheet(title = tag, rows=100, cols=20)
     18 worksheet.update([df.columns.values.tolist()] + df.values.tolist())

AttributeError: 'tuple' object has no attribute 'open'
1

There are 1 answers

2
Nick ODell On

If you look at the docs for the gspread project, they have an example for this function:

gc, authorized_user = gspread.oauth_from_dict(credentials)

Notice there are two values before the equals.

More information: https://docs.gspread.org/en/latest/oauth2.html