Issue switching from snowpark connection to snowflake connection

Hi team

I have this streamlit app published in Snowflake. It has been working fine since published. However, I am getting this warning that the st.connection(''snowpark") will be removed.

When I tried switching from st.connection(“snowpark”) to st.connection(“snowflake”) as suggested in the warning message, I am getting this error:

Error message:
ImportError: cannot import name ‘BAD_REQUEST_GS_CODE’ from ‘snowflake.connector.network’ (/usr/lib/python_udf/9c6deab4ddfeb6ccf4ef50d22ad9d986333cdb8f976bcaf62df77ced42366ee3/lib/python3.8/site-packages/snowflake/connector/network.py)

Traceback:

File "/usr/lib/python_udf/9c6deab4ddfeb6ccf4ef50d22ad9d986333cdb8f976bcaf62df77ced42366ee3/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 540, in _run_script
    exec(code, module.__dict__)File "/tmp/appRoot/streamlit_app.py", line 13, in <module>
    df = conn.query("SELECT * from TEST_LANDING.HCPTOOL.CLIENT_CONTRIBUTION;", ttl=600)File "/usr/lib/python_udf/9c6deab4ddfeb6ccf4ef50d22ad9d986333cdb8f976bcaf62df77ced42366ee3/lib/python3.8/site-packages/streamlit/connections/snowflake_connection.py", line 169, in query
    from snowflake.connector.network import (  # type: ignore[import]

This is the code that I am using to test the new connection:

 # streamlit_app.py

import streamlit as st

# Initialize connection.
conn = st.connection("snowflake")

# Perform query.
df = conn.query("SELECT * from TEST_LANDING.HCPTOOL.CLIENT_CONTRIBUTION;", ttl=600)

I can’t seem to find any topic on this. Could you kindly help please?
Many thanks

Hey @Aaron,

Thanks for sharing this question! Have you installed snowflake-connector-python?

thank you Caroline for replying.

I am running Streamlit within Snowflake. Is the connector still required?

These are the packages installed:
image

Is there any documentation about how to install the connector through Snowsight?

Thanks

Hey @Aaron,

Sorry for the confusion! I missed that you were running the app in Streamlit in Snowflake.

In that case, you shouldn’t need to install the Snowflake Python connector, but I’d actually recommend doing the following instead to access Snowflake data from your Streamlit-in-Snowflake app (and here’s a doc with this code):

import streamlit as st
from snowflake.snowpark.context import get_active_session

session = get_active_session()
sql = f"select * from snowflake_sample_data.tpch_sf1.lineitem limit 20"
data = session.sql(sql).to_pandas()