Changing the experimental_get_query_params to query_params throwing error

Still learning but can someone explain to change the deprecated ‘experimental_get_query_params’ to ‘query_params’ simply?

If I change this:

        if 'code' not in st.experimental_get_query_params():
            show_auth_link(config, label)
        code = st.experimental_get_query_params()['code'][0]
        state = st.experimental_get_query_params()['state'][0]

to this:

        if 'code' not in st.query_params():
            show_auth_link(config, label)
        code = st.query_params()['code'][0]
        state = st.query_params()['state'][0]

I see this error:
TypeError: ‘QueryParamsProxy’ object is not callable

prior to this code change I did from this which is ALSO throwing an error:

From this:

st.experimental_set_query_params(**qparms)

To this:

st.query_params["key"] = qparms

I see the error:

StreamlitAPIException : You cannot set a query params key key to a dictionary.

1 Like

Hello @KristiVice1,

When you switch from st.experimental_get_query_params() to st.query_params , you need to adjust how you access the properties. st.query_params is no longer a method (callable) but a property (non-callable) that returns a dictionary-like object of the current session’s query parameters.

if 'code' not in st.session_state.query_params:
    show_auth_link(config, label)
code = st.session_state.query_params['code'][0]
state = st.session_state.query_params['state'][0]

The correct approach after the API change is:

query_params = st.experimental_get_query_params()  # This is the old way

if 'code' not in st.query_params:
    show_auth_link(config, label)
code = st.query_params['code'][0]
state = st.query_params['state'][0]

Hope this helps!

Kind Regards,
Sahir Maharaj
Data Scientist | AI Engineer

P.S. Lets connect on LinkedIn!

➤ Want me to build your solution? Lets chat about how I can assist!
➤ Join my Medium community of 30k readers! Sharing my knowledge about data science and AI
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ 100+ FREE Power BI Themes: Download Now

3 Likes

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