Error on deploy (pyodbc)

Hi, I’m working on a project where I access MySQL to fetch data.
The app works perfectly when running it locally. But when I deploy, it returns this error:
in module

connect = pyodbc.connect(connection_string)

pyodbc.Error: (‘01000’, “[01000] [unixODBC][Driver Manager]Can’t open lib ‘SQL Server’ : file not found (0) (SQLDriverConnect)”)

Unfortunatelly I can’t share the app because it is private. Does anyone know how to solve this? It is NOT a problem with requirements.txt

Try to search that error message using bing.

Thanks, I found the error and made changes, but now I get this message:

in init_connection
    return pyodbc.connect(
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

My code is:
import pyodbc
import pandas as pd
import streamlit as st
from sqlalchemy import create_engine

#connection function
@st.cache_resource
def init_connection():
return pyodbc.connect(
“DRIVER={ODBC Driver 17 for SQL Server};SERVER=”
+ st.secrets[“server”]
+ “;DATABASE=”
+ st.secrets[“database”]
+ “;UID=”
+ st.secrets[“username”]
+ “;PWD=”
+ st.secrets[“password”]
)

connect = init_connection()

@st.experimental_memo(ttl=300) #timer in seconds to update de database
def run_query(query):
with connect.cursor() as cursor:
cursor.execute(query)
return cursor.fetchall()

cursor = connect.cursor()

#creating queries
query_saldo_estoque = run_query(“”““”“)
query_pedidos_faturar = run_query(”“”
”“”)

#reading data
saldo_estoque = pd.read_sql(query_saldo_estoque, connect)
pedidos_faturar = pd.read_sql(query_pedidos_faturar, connect)

#creating dataframe
df_saldo_estoque = pd.DataFrame.from_dict(saldo_estoque)
df_pedidos_faturar = pd.DataFrame.from_dict(pedidos_faturar)

#closing connection
cursor.close()


I had to censor the run_query

1 Like