App fails to read secrets/environment variables for Google Sheets connection

Hello,
My Streamlit app cannot connect to Google Sheets because it’s unable to read the credentials from the environment variables. The error is No Google client config found.
I have confirmed the following:

  • The Python code for decoding the Base64 credential and connecting works perfectly when the credential string is hardcoded directly in the script.
    I have tried configuring the secret using both secrets.toml and the [env] section for environment variables.
    The app is not finding the key (GCP_CREDS_B64).
    I have rebooted the app many times.
    My service account key is active and has the correct permissions.
    It seems there is a synchronization issue with my app’s environment on Streamlit Cloud.
    Here is my function to get the client:
    @st.cache_resource
    def get_google_sheets_client():
    creds_b64_str = os.environ.get(“GCP_CREDS_B64”)
    if not creds_b64_str:
    st.error(“Error de Sincronización: No se encontró la variable de entorno ‘GCP_CREDS_B64’. Asegúrate de que los cambios en GitHub y en los Secrets de Streamlit se hayan guardado y reinicia la app.”)
    return None
    try:
    creds_bytes = base64.b64decode(creds_b64_str)
    creds_json_str = creds_bytes.decode(‘utf-8’)
    creds_dict = json.loads(creds_json_str)
    gspread_client = gspread.service_account_from_dict(creds_dict)
    return gspread_client
    except Exception as e:
    st.error(“FALLO CRÍTICO AL PROCESAR LAS CREDENCIALES.”)
    st.code(f"Detalle técnico: {e}", language=“text”)
    return None
    Here is the link to my public GitHub repository: GitHub - Leoreo148/Proyecto-uva: El programa más chingón del mundo
    Can you please help me understand why my deployed app is not loading the environment variables?
    And Yes, it is made with the help of AI
    Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.