diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 68dc8d60..83c891bc 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -19,6 +19,7 @@ Changelog This fixes a bug where pandas-gbq could not refresh credentials if the cached credentials were invalid, revoked, or expired, even when ``reauth=True``. +- Catch RefreshError when trying credentials. (:issue:`226`) Internal changes ~~~~~~~~~~~~~~~~ diff --git a/pandas_gbq/auth.py b/pandas_gbq/auth.py index 86ad929a..9f32bac7 100644 --- a/pandas_gbq/auth.py +++ b/pandas_gbq/auth.py @@ -297,6 +297,7 @@ def save_user_account_credentials(credentials, credentials_path): def _try_credentials(project_id, credentials): from google.cloud import bigquery import google.api_core.exceptions + import google.auth.exceptions if not credentials: return None @@ -310,3 +311,9 @@ def _try_credentials(project_id, credentials): return credentials except google.api_core.exceptions.GoogleAPIError: return None + except google.auth.exceptions.RefreshError: + # Sometimes (such as on Travis) google-auth returns GCE credentials, + # but fetching the token for those credentials doesn't actually work. + # See: + # https://github.com/googleapis/google-auth-library-python/issues/287 + return None