What I’m trying to do:
Hello! I have a Colab program that asks the user for their name to access or create a bucket in Google Cloud Storage. Considering the files that exist in that bucket, the user begins an interaction with a chatbot based on vertex ai.
The interface created in Anvil works perfectly as long as I have run my Colab code and have made the authentications from there.
I want to move the entire program to Anvil, but I have had several problems with authentication to access my GCS from Anvil.
What I’ve tried and what’s not working:
I have tried the following method inside a fuction to check if it can login succesfully:
Code Sample:
def authenticate_and_list_buckets():
if not os.path.exists(data_files['client_secret_.json']):
with open(data_files['client_secret_.json'], "rb") as f:
print(f.read())
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = data_files['client_secret_.json']
project_id = "project123"
storage_client = storage.Client(project=project123)
try:
buckets = list(storage_client.list_buckets())
if buckets:
return [bucket.name for bucket in buckets]
else:
return "Autenticación exitosa, pero no se encontraron buckets."
except Exception as e:
return f"Error al autenticar: {e}" ```
**Thanks for advance**