Pandas read_csv from Google Cloud Storage?

I am trying to read in a .csv from Google Cloud Storage in a Streamlit Cloud app. When I am testing locally, the following code works with no issues:

credentials = service_account.Credentials.from_service_account_info(
    st.secrets['gcp_service_account'], scopes=[""])

data = pd.read_csv(path,
                    storage_options={'token' : credentials},

However when I deploy to Streamlit Cloud, I am getting the following error:

KeyError: 'st.secrets has no key "gcp_service_account". Did you forget to add it to secrets.toml or the app settings on Streamlit Cloud? More info:'

I copied and pasted the credentials exactly the same as the secrets.toml I have locally into the secrets manager for Streamlit Cloud.

When I read the docs concerning Secrets Management, I noticed the syntax for calling an entire section of the toml file was as follows:


Is this just a simple syntax error on my part? Are the double asterisks (**) doing something here that I’m not understanding? Thank you!

Just an update here-- simple solution. When first creating the Streamlit app, my .toml section header [gcp_service_account] did not save for some reason. Going into the app settings, and modifying the secrets to include the section header made things work no problem.

1 Like

Hello Nate,
How did you the code in your app to include the secrets files? I can’t seem to complete the connection.

Here is mine but I get an error message to add another module and ‘no module named oauthlib’

credentials = service_account.Credentials.from_service_account_info(