I’m running the app locally as follows:
Streamlit 1.28.2
Python 3.12
I have the following single file that I run streamlit run sample.py
. I want GetToken() to run once, but it runs over and over again.
import toml
import requests
import json
import pandas as pd
import streamlit as st
accounts = st.secrets["accounts"]
initial_token = st.secrets["refresh_token"]
url = st.secrets["api_server"]
def getToken():
# get a new refresh token and populate variables
r = json.loads(
requests.get(
f"https://login.something.com/oauth2/token?grant_type=refresh_token&refresh_token={initial_token}"
).text
)
# url = r["api_server"]
access_token = r["access_token"]
refresh_token = r["refresh_token"]
header = {"Authorization": f"Bearer {refresh_token}"}
data = toml.load(".streamlit/secrets.toml")
data["refresh_token"] = refresh_token
data["access_token"] = access_token
data["header"] = header
# data["api_server"] = url
f = open(".streamlit/secrets.toml", "w")
toml.dump(data, f)
f.close()
pass
if __name__ == "__main__":
getToken()