Я настраиваю Docker-контейнер для своего приложения, в котором я хочу подключить код Python к серверу Microsoft SQL.
Ниже приведены настройки и код Python
odbcinst.ini
[FreeTDS]Description=FreeTDS unixODBC Driver Driver=/usr/lib/x86_64-
linux-gnu/odbc/libtdsodbc.so Setup=/usr/lib/x86_64-linux-
gnu/odbc/libtdsS.so
Python
import pyodbc
server = '127.0.0.1'
db = 'bd1'
drivers = [item for item in pyodbc.drivers()]
driver = drivers[-1]
engine = create_engine('mssql+pyodbc://' + server + '/' + db + "?" +
driver)
conn = pyodbc.connect('DRIVER={driver};SERVER=' + server +
';PORT=1433;DATABASE=' + db + ';UID=SA;PWD=MyPass123!')
Docker-compose.yml
version: '3'
services:
pyth:
build: .
ports:
- "5000:5000"
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "MyPass123!"
ACCEPT_EULA: "Y"
ports:
- "1433:1433"
Это ошибка, которую я получаю
"No driver name specified; "
pyth_1 | Traceback (most recent call last):
pyth_1 | File "testing_sql.py", line 15, in <module>
pyth_1 | conn = pyodbc.connect('DRIVER={driver};SERVER=' + server + ';PORT=1433;DATABASE=' + db + ';UID=SA;PWD=MyPass123!')
pyth_1 | pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'driver' : file not found (0) (SQLDriverConnect)")