Streamlit.scriptrunner on streamlit 1.13.0

Hello,

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']

How can I solve? Thank you

no one is able to answer? I still can’t update

thank you

Hi @Fabio_Pasquarella :wave:

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
  ...
1 Like

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'
1 Like

That change happened after Streamlit 1.13.0 was released. You can try a nightly release.

1 Like

It also works on 1.14.0rc1.

2 Likes

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