Summary
I am trying to connect to a private google sheets using Streamlit and Python, however the code is getting stuck at “result = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()”, but when I run the code using normal python (python3 app.py) it works without any issue
Steps to reproduce
Code snippet:
@st.cache(ttl=600)
def run_query(sheet_url,_credentials):
try:
print(f"Attempting to connect to Google Sheets API using credentials: {_credentials}")
service = discovery.build('sheets', 'v4', credentials=_credentials)
spreadsheet_id = ''
range_name = 'Sheet1'
print(f"Attempting to fetch data from Google Sheets API")
result = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()
rows = result.get('values', [])
print(f"Successfully retrieved {len(rows)} rows from {sheet_url}")
return rows
except Exception as e:
print(f"Error retrieving data from {sheet_url}: {e}")
raise e
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
it should print successfully fetched lines from
Actual behavior:
its getting stuck at “result = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id, range=range_name).execute()”
Debug info
- Streamlit version: 1.22.0
- Python version: 3.11.2
- Using Conda? PipEnv? PyEnv? Pex? : No
- OS version: Mac OS ventura 13.3.1
- Browser version: Chrome Version 112.0.5615.137