You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an error when using the following three components in the same streamlit app:
authentication with hmac
a st_folium map component
an api call with requests that returns json
Plotting the map and making the api call in that sequence seems to be clearing the session_state and results in failed authentication. The error does not occur when using folium_static, so I assume the issue is with streamlit-folium, but apologies if my judgement is wrong.
The full error:
2024-10-18 14:55:31.107 Uncaught app exception
Traceback (most recent call last):
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 455, in __getitem__
return self._getitem(widget_id, key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 500, in _getitem
raise KeyError
KeyError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 541, in code_to_exec
self._session_state.on_script_will_rerun(
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/safe_session_state.py", line 66, in on_script_will_rerun
self._state.on_script_will_rerun(latest_widget_states)
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 559, in on_script_will_rerun
self._call_callbacks()
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 572, in _call_callbacks
self._new_widget_state.call_callback(wid)
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 273, in call_callback
callback(*args, **kwargs)
File "/home/anna/test/app.py", line 14, in password_entered
if hmac.compare_digest(st.session_state["password"], st.secrets["password"]):
~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state_proxy.py", line 100, in __getitem__
return get_session_state()[key]
~~~~~~~~~~~~~~~~~~~^^^^^
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/safe_session_state.py", line 94, in __getitem__
return self._state[key]
~~~~~~~~~~~^^^^^
File "/home/anna/test/.env/lib/python3.12/site-packages/streamlit/runtime/state/session_state.py", line 457, in __getitem__
raise KeyError(_missing_key_error_message(key))
KeyError: 'st.session_state has no key "password". Did you forget to initialize it? More info: https://docs.streamlit.io/develop/concepts/architecture/session-state#initialization'
Minimum example to reproduce:
import hmac
import folium
import requests
import streamlit as st
from streamlit_folium import folium_static, st_folium
def check_password():
"""Returns `True` if the user had the correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if hmac.compare_digest(st.session_state["password"], st.secrets["password"]):
st.session_state["password_correct"] = True
del st.session_state["password"] # Don't store the password.
else:
st.session_state["password_correct"] = False
# Return True if the password is validated.
if st.session_state.get("password_correct", False):
return True
# Show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password"
)
if "password_correct" in st.session_state:
st.error("😕 Password incorrect")
return False
if not check_password():
st.stop() # Do not continue if check_password is not True.
map = folium.Map()
st_folium(map)
# folium_static(map)
# url = "http://example.com"
url = "https://api.sampleapis.com/coffee/hot"
response = requests.get(url)
st.write("Response:", response.json())
The error does not occur if st_folium is replaced with folium_static or "https://api.sampleapis.com/coffee/hot" is replaced with "http://example.com" (json vs plain text) or if the api request is made before plotting the map.
First of all, thanks for the great tool!
I ran into an error when using the following three components in the same streamlit app:
hmac
st_folium
map componentrequests
that returns jsonPlotting the map and making the api call in that sequence seems to be clearing the
session_state
and results in failed authentication. The error does not occur when usingfolium_static
, so I assume the issue is withstreamlit-folium
, but apologies if my judgement is wrong.The full error:
Minimum example to reproduce:
The error does not occur if
st_folium
is replaced withfolium_static
or "https://api.sampleapis.com/coffee/hot" is replaced with "http://example.com" (json vs plain text) or if the api request is made before plotting the map.Python environment:
Other details:
The text was updated successfully, but these errors were encountered: