I have an app on aws that runs on streamlit==1.11.1, but since then I can’t update anymore because of this error:
ModuleNotFoundError: No module named ‘streamlit.scriptrunner’
Traceback:
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 562, in _run_script
exec(code, module.dict)
File “/app/freya.py”, line 12, in
from streamlit.scriptrunner.script_run_context import get_script_run_ctx
it seems something changed in internal logic of streamlit code. Here’s the snippet:
import streamlit as st
from streamlit.scriptrunner.script_run_context import get_script_run_ctx
from streamlit.server.server import Server
# Get Cognito User ID from request headers
def get_userid():
session_id = get_script_run_ctx().session_id
session_info = Server.get_current()._get_session_info(session_id)
if session_info is None:
raise RuntimeError('Could not get your Streamlit Session object.')
if session_info.ws is None:
return None
headers = session_info.ws.request.headers
if not headers or 'X-Amzn-Oidc-Identity' not in headers:
raise RuntimeError('User ID not found in load balancer authentication headers')
return headers['X-Amzn-Oidc-Identity']
Please take a look at the following pull request to learn how to update your code:
We have a new “internal” (i.e.: subject to change without deprecation!) API to access a copy of the headers from the current session’s incoming WebSocket request.:
import streamlit as st
from streamlit.web.server.websocket_headers import _get_websocket_headers
headers = _get_websocket_headers()
access_token = headers.get("X-Access-Token")
if access_token is not None:
# authenticate the user or whatever
...
I’m facing the same problem as OP.
Your snippet doesn’t solve my problem. I’m using streamlit 1.13.0 and with
from streamlit.web.server.websocket_headers import _get_websocket_headers
I now get the error
File ".../demo.py", line 2, in <module>
from streamlit.web.server.websocket_headers import _get_websocket_headers
ModuleNotFoundError: No module named 'streamlit.web.server.websocket_headers'
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.