Streamlit URL (with querystring) will work from a browser, but not through a direct python requests

I want to be able to have special treatment of my Streamlit app depending on some QueryString params.

I’m able to test these querystrings on the browser, but if I attempt using python request.get() to simulate a call with querystring params I always get access denied errors. My app doesn’t have any auth methods anywhere.

Why am I only able to use Streamlit in a browser but not on a simple requests.get() call? Do I need some special params on this call?

Seems to work for me.

I got around this “access denied” issue. It was actually a proxy problem.
No I am managing to call Streamlit either from a python requests() call or via cURL.

But I always receive a response like the one below. I am pasting my very simple code which is not working as expected, I never get the “querystring if” to work.

ingest-upload) [ec2-user@ip-172-16-1-126 ingest-upload]$ curl http://localhost:8501?test=upload
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><link rel="shortcut icon"href="./favicon.png"/><title>Streamlit</title><script>window.prerenderReady=!1</script><script src="./vendor/viz/viz-1.8.0.min.js" type="javascript/worker"></script><script src="./vendor/bokeh/bokeh-2.4.3.min.js"></script><script src="./vendor/bokeh/bokeh-widgets-2.4.3.min.js"></script><script src="./vendor/bokeh/bokeh-tables-2.4.3.min.js"></script><script src="./vendor/bokeh/bokeh-api-2.4.3.min.js"></script><script src="./vendor/bokeh/bokeh-gl-2.4.3.min.js"></script><script src="./vendor/bokeh/bokeh-mathjax-2.4.3.min.js"></script><script defer="defer" src="./static/js/main.8a695abc.js"></script><link href="./static/css/main.f4a8738f.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>(ingest-upload) [ec2-user@ip-172-16-1-126 ingest-upload]$

Here’s what I’m trying to do:

import streamlit as st
import os

query_params = st.experimental_get_query_params()
print(query_params)

if not query_params:
    st.title('Streamlit Homepage')
    print('No query string')
else:
    if query_params:
        print('There is a query string:')
        print(query_params)

The body of the response says it all:

You need to enable JavaScript to run this app.

curl can download the html but it won’t run the javascript. You need an actual browser for that.

Hi Goyo, that much I got from the returned HTML.

Am I only able to interact with Streamlit via a browser?

Why can’t I use cURL, wget or just a regular Python requests() call?

Because they are unable to run the javascript.

1 Like

What if I don’t want any Javascript? I just want to serve very simple raw data (like in the example code above), depending on the query string.

Is that impossible via Streamlit?

This is what I want to know in order to know if it serves my use case.

Streamlit is a framework for converting python code to a web app. That web app requires javascript to render. There is no version of streamlit that doesn’t require javascript to render.

However, there are alternatives to vanilla requests that do support running javascript, such as requests-html · PyPI

But, if you simply want to serve simple data in response to query params, and don’t actually want a UI frontend, then you would probably be better off using something like FastAPI or Flask.

1 Like

Thanks a lot for that detailed reply. Now I know what to do.
Have a good day.