Hello,
I’m new here but am trying to run my streamlit app but as it starts up, I get the error:
Exception in callback AppSession._on_scriptrunner_event..() at /usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py:518
handle: <Handle AppSession._on_scriptrunner_event..() at /usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py:518>
Traceback (most recent call last):
File “/usr/local/lib/python3.9/site-packages/streamlit/web/bootstrap.py”, line 347, in run
if asyncio.get_running_loop().is_running():
RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.9/asyncio/events.py”, line 80, in _run
self._context.run(self._callback, *self._args)
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py”, line 518, in
lambda: self._handle_scriptrunner_event_on_event_loop(
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py”, line 612, in _handle_scriptrunner_event_on_event_loop
msg = self._create_new_session_message(
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py”, line 742, in _create_new_session_message
_populate_user_info_msg(imsg.user_info)
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/app_session.py”, line 990, in _populate_user_info_msg
inst = Installation.instance()
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/metrics_util.py”, line 228, in instance
cls._instance = Installation()
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/metrics_util.py”, line 236, in _init_
self.installation_id_v4 = _get_machine_id_v4()
File “/usr/local/lib/python3.9/site-packages/streamlit/runtime/metrics_util.py”, line 209, in _get_machine_id_v4
with file_util.streamlit_write(filepath) as output:
File “/usr/local/lib/python3.9/contextlib.py”, line 119, in _enter_
return next(self.gen)
File “/usr/local/lib/python3.9/site-packages/streamlit/file_util.py”, line 109, in streamlit_write
os.makedirs(os.path.dirname(path), exist_ok=True)
File “/usr/local/lib/python3.9/os.py”, line 225, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: ‘/.streamlit’

**Any recommendations on how to address this?
**
My Docker is extremely simple:
FROM python:3.9-slim

WORKDIR /app

COPY . .

RUN pip3 install -r requirements.txt

CMD [“streamlit”, “run”, “app.py”, “–server.port=7860”, “–server.address=0.0.0.0”, “–server.enableXsrfProtection=false”]

Thanks in advance for any help!

1 Like

How about like this?

FROM python:3.9-slim

# Create non-root user that matches Spaces runtime (uid 1000), set HOME
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app

# Install deps as the user
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy app code with correct ownership
COPY --chown=user . .

# Optional: project config; Streamlit also reads $CWD/.streamlit/config.toml
# (this avoids reliance on ~/.streamlit)
# COPY --chown=user .streamlit $HOME/app/.streamlit

EXPOSE 8501
ENTRYPOINT ["streamlit","run","app.py","--server.port=8501","--server.address=0.0.0.0"]
1 Like

Thanks, John6666! I’m getting a new error when using the app. Essentially, I have a front end that takes a collection of inputs and sends it to another space that have my backend model which should render a prediction and send it back to the frontend space. Is this a permission issue or do I need a specific SSL cert?

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘marioandrade-superkart_backend.hf.space’, port=443): Max retries exceeded with url: /v1/predict (Caused by SSLError(SSLCertVerificationError(1, “[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for ‘marioandrade-superkart_backend.hf.space’. (_ssl.c:1147)”)))

Traceback:

File "/home/user/app/app.py", line 33, in <module>
    response = requests.post("https://MarioAndrade-SuperKart_backend.hf.space/v1/predict", json=product_data)    

File "/home/user/.local/lib/python3.9/site-packages/requests/api.py", line 115, in post return request("post", url, data=data, json=json, **kwargs)

File "/home/user/.local/lib/python3.9/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs)

File "/home/user/.local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs)

File "/home/user/.local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs)

File "/home/user/.local/lib/python3.9/site-packages/requests/adapters.py", line 698, in send raise SSLError(e, request=request)

1 Like

https://MarioAndrade-SuperKart_backend.hf.space

https://marioandrade-superkart-backend.hf.space/
I think this format is necessary because underscores cannot be used in subdomains.
Embed your Space in another website

Both suggestions really helped! Now I’m trying to resolve an error where the Flask app (post from Streamlit) is returning a 404 even though Flask has app.post(‘/v1/predict’) and Streamlit is using exact URL to post json object. Not sure why it would return a 404…

1 Like

It seems that errors often occur depending on whether there is a slash or not (/v1/predict vs /v1/predict/).
Well, if that’s the case, it’s easy…:sweat_smile:

1 Like

I was hopeful that would work but unfortunately, it’s the same error. :frowning:

1 Like

The spaces were set to private. I made them public and it worked. :rofl:

Thanks for your help, John!

1 Like