File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,18 @@ def default(
157157 return credentials , None
158158
159159
160+ def _ensure_application_default_credentials_in_colab_environment ():
161+ # This is a special handling for google colab environment where we want to
162+ # use the colab specific authentication flow
163+ # https://github.com/googlecolab/colabtools/blob/3c8772efd332289e1c6d1204826b0915d22b5b95/google/colab/auth.py#L209
164+ try :
165+ from google .colab import auth
166+
167+ auth .authenticate_user ()
168+ except (ModuleNotFoundError , ImportError ):
169+ pass
170+
171+
160172def get_application_default_credentials (scopes ):
161173 """
162174 This method tries to retrieve the "default application credentials".
@@ -178,6 +190,8 @@ def get_application_default_credentials(scopes):
178190 have access to the project (project_id) on BigQuery.
179191 """
180192
193+ _ensure_application_default_credentials_in_colab_environment ()
194+
181195 try :
182196 credentials , project = google .auth .default (scopes = scopes )
183197 except (google .auth .exceptions .DefaultCredentialsError , IOError ) as exc :
You can’t perform that action at this time.
0 commit comments