Last active
January 19, 2021 07:49
-
-
Save korakot/d20898abfb9f6ee257d3e9d5c7700c96 to your computer and use it in GitHub Desktop.
Use requests with Google default credentials in Colab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import google.auth | |
from google.auth.transport.requests import AuthorizedSession | |
# login | |
from google.colab import auth | |
auth.authenticate_user() | |
# use default credentials to create session | |
cred = google.auth.default()[0] # for cred.token | |
s = AuthorizedSession(cred) | |
# s.get or s.post | |
url = 'https://storage.googleapis.com/storage/v1/b/co-lab' | |
s.get(url).json() # show result | |
# using kora | |
from kora.gcloud import session | |
s = session() | |
s.get(url).json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment