# Error executing query

**URL:** <https://discuss.streamlit.io/t/error-executing-query/26919>\
**Category:** Community Cloud\
**Created:** [June 24, 2022, 2:37am UTC](https://discuss.streamlit.io/t/error-executing-query/26919 "2022-06-24T02:37:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Moralls](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mark_moralls/32/3096_2.png) [@Mark\_Moralls](https://discuss.streamlit.io/u/Mark_Moralls)\
**Post date:** [June 24, 2022, 2:37am UTC](https://discuss.streamlit.io/t/error-executing-query/26919/1 "2022-06-24T02:37:02Z")

</div>

Hello,

I’ve looked in vain for an answer to my issue. I have a db web app that runs fine locally and I have deployed for users to access. It has predefined SQL queries that can be executed with results from BigQuery. It uses pandas\_gbq library to process the queries. I have the secrets file saved accordingly and the contents in my app’s secret section. I get the following error message when I try and execute a query:

pandas\_gbq.exceptions.GenericGBQException: Reason: 401 POST [https://bigquery.googleapis.com/bigquery/v2/projects/s4a-prod/jobs?prettyPrint=false:](https://bigquery.googleapis.com/bigquery/v2/projects/s4a-prod/jobs?prettyPrint=false:) Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See [Integrating Google Sign-In into your web app &nbsp;|&nbsp; Google Sign-In for Websites &nbsp;|&nbsp; Google Developers](https://developers.google.com/identity/sign-in/web/devconsole-project).

BigQuery API is enabled. In the Credentials tab I have an API key with HTTP referrers and an OAuth 2.0 Client ID. BigQuery API and BigQuery Data Transfer API are the API restricted. I’ve added [https://oauth2.googleapis.com/token](https://oauth2.googleapis.com/token) in the Authorized redirect URI field and [https://share.streamlit.io](https://share.streamlit.io) in the Authorized Javascript origins field.

I don’t know what I am missing. Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [June 27, 2022, 2:08pm UTC](https://discuss.streamlit.io/t/error-executing-query/26919/2 "2022-06-27T14:08:58Z")

</div>

That’s a strange one @Mark_Moralls. When you copied your secrets into the interface, did you make sure to convert it to toml instead of the JSON that Google usually provides?

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [June 28, 2022, 1:23pm UTC](https://discuss.streamlit.io/t/error-executing-query/26919/3 "2022-06-28T13:23:56Z")

</div>

Hi @Mark_Moralls -

We played around internally a bit, we think this might be a case of not setting a `project_id`. Because Streamlit Cloud is hosted on Google Cloud, it looks like the Python library infers a project you don’t have access to.

So check that value in the Secrets interface and let us know if that resolves it.

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![Mark\_Moralls](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mark_moralls/32/3096_2.png) [@Mark\_Moralls](https://discuss.streamlit.io/u/Mark_Moralls)\
**Post date:** [June 28, 2022, 6:22pm UTC](https://discuss.streamlit.io/t/error-executing-query/26919/4 "2022-06-28T18:22:21Z")

</div>

Hi Randy,

Thanks for looking into my issue. Yes, it was a strange one and I did verify the secrets file to TOML format. I thought the credentials line was enough to make the connection to the project id.

credentials = service\_account.Credentials.from\_service\_account\_info(  
st.secrets[“gcp\_service\_account”]

So after going back to the pandas\_gbq documentation, I did set a project id variable and added project\_id and credentials to each of my df variable entries:

df = pandas\_gbq.read\_gbq(contents, **project\_id, credentials=credentials** )

So now each query works as I intended! Glad this was resolved. Thanks again!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [June 28, 2023, 6:22pm UTC](https://discuss.streamlit.io/t/error-executing-query/26919/5 "2023-06-28T18:22:38Z")

</div>

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