I am trying to use python in a virtual environment to write a dataframe to sql server. I can read from the server with my pyodbc connection, but can't write to it using that connection, so I'm using a sqlalchemy engine, and credentials stored in a .env file.
Printing the raw string returns:
'mssql+pyodbc://User:Password@Server/Database?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'
but when printing the engine it returns:
'mssql+pyodbc://User:***sword@Server/Database?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'
If I try to connect using the engine, the login timeout expires, which I'm assuming is because the engine isn't passing the correct credentials.
Is there something going on with my string formatting?
import os
from sqlalchemy import create_engine
from dotenv import load_dotenv
load_dotenv()
credentials = [os.getenv('UID'), os.getenv('PWD'), os.getenv('Server'), os.getenv('Database')]
engine = create_engine('mssql+pyodbc://{0}:{1}@{2}/{3}?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'.format(*credentials),fast_executemany=True)
print('mssql+pyodbc://{0}:{1}@{2}/{3}?trusted_connection=no&driver=ODBC+Driver+17+for+SQL+Server'.format(*credentials))
print(engine)
engine.connect()