I'm new to python and currently is working on a project that requires me to export pandas data frame from google collab to a google spreadsheet with multiple tabs. Previously when I run this specific code, there are no errors but then now it shows an error like this:
TypeError Traceback (most recent call last)
<ipython-input-74-c8b829c43616> in <module>()
5 gauth.credentials = GoogleCredentials.get_application_default()
6 drive = GoogleDrive(gauth)
----> 7 gc = gspread.authorize(GoogleCredentials.get_application_default())
2 frames
/usr/local/lib/python3.7/dist-packages/gspread/utils.py in convert_credentials(credentials)
59
60 raise TypeError(
---> 61 'Credentials need to be from either oauth2client or from google-auth.'
62 )
63
TypeError: Credentials need to be from either oauth2client or from google-auth.
Here is the code that I use to create authentication.
#Import PyDrive and associated libraries.
#This only needs to be done once per notebook.
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
import gspread
#Authenticate and create the PyDrive client.
#This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
gc = gspread.authorize(GoogleCredentials.get_application_default())
Any help would be much appreciated.
CodePudding user response:
I'm also experiencing the same issues with colab. I assume it's from google. Here's my own code:
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
CodePudding user response:
It was solved here: https://github.com/burnash/gspread/issues/1014#issuecomment-1082536016
I think there must be some changes on Google side.